Skip to content

Commit

Permalink
Prefer list comprehension to tuple for speed
Browse files Browse the repository at this point in the history
  • Loading branch information
zwimer committed Jan 9, 2025
1 parent de111fb commit 269a8bb
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion rpipe/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__: str = "9.5.3" # Must be "<major>.<minor>.<patch>", all numbers
__version__: str = "9.5.4" # Must be "<major>.<minor>.<patch>", all numbers
4 changes: 2 additions & 2 deletions rpipe/client/client/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ def decrypt(data: bytes, decompress: Callable[[bytes], bytes], password: str | N
es = _EncryptedData.decode(data)
sfx = "s" if len(es) != 1 else ""
log.debug("Decrypting %d chunk%s", len(es), sfx)
r = tuple(_aes(e.salt, password, e.nonce).decrypt_and_verify(e.text, e.tag) for e in es)
r = [_aes(e.salt, password, e.nonce).decrypt_and_verify(e.text, e.tag) for e in es]
log.debug("Decompressing %d chunk%s", len(es), sfx)
r = tuple(decompress(i) for i in r)
r = [decompress(i) for i in r]
if len(es) > 1:
log.debug("Merging chunks")
return r[0] if len(r) == 1 else b"".join(r)
8 changes: 4 additions & 4 deletions rpipe/client/client/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ def channel_url(self) -> str:
return f"{self.url}/c/{quote(self.channel)}"

@classmethod
def keys(cls) -> tuple[str, ...]:
return tuple(i.name for i in fields(cls))
def keys(cls) -> list[str]:
return [i.name for i in fields(cls)]

@classmethod
def load(cls, cli: dict[str, bool | str | Path | None], file: Path) -> Self:
Expand Down Expand Up @@ -146,8 +146,8 @@ class Mode:
checksum: bool

@classmethod
def keys(cls) -> tuple[str, ...]:
return tuple(i.name for i in fields(cls))
def keys(cls) -> list[str]:
return [i.name for i in fields(cls)]

def priority(self) -> bool:
c = (self.print_config, self.save_config, self.outdated, self.server_version, self.query).count(True)
Expand Down
2 changes: 1 addition & 1 deletion rpipe/server/channel/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def read(state: State, channel: str) -> Response:
if not args.delete: # Peek mode (could also be web version)
log.debug("Reading channel %s in peek mode", channel)
u.stats.peek(channel)
rdata: Sequence[bytes] = tuple(s.data)
rdata: Sequence[bytes] = s.data
final = True
elif args.version == WEB_VERSION:
log.debug("Reading channel %s from WEB_VERSION", channel)
Expand Down
2 changes: 1 addition & 1 deletion rpipe/server/server/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def load(self, file: Path) -> None:
return
self._log.debug("Creating server Stats")
self.stats = Stats()
_ = tuple(self.stats.channels[i] for i in self.streams)
_ = [self.stats.channels[i] for i in self.streams]
self._log.info("State loaded successfully")

def save(self, file: Path) -> None:
Expand Down

0 comments on commit 269a8bb

Please sign in to comment.