Skip to content

Commit 80cebcf

Browse files
authored
Refactor _skip_sync for Improved Readability & Performance (#3343)
1 parent 7da3211 commit 80cebcf

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

lang/py/avro/datafile.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -387,13 +387,13 @@ def _read_block_header(self) -> None:
387387

388388
def _skip_sync(self) -> bool:
389389
"""
390-
Read the length of the sync marker; if it matches the sync marker,
391-
return True. Otherwise, seek back to where we started and return False.
390+
Check if the next bytes match the sync marker.
391+
If not, rewind the read position.
392392
"""
393-
proposed_sync_marker = self.reader.read(SYNC_SIZE)
394-
if proposed_sync_marker == self.sync_marker:
393+
pos = self.reader.tell()
394+
if self.reader.read(SYNC_SIZE) == self.sync_marker:
395395
return True
396-
self.reader.seek(-SYNC_SIZE, 1)
396+
self.reader.seek(pos) # Reset position if sync doesn't match
397397
return False
398398

399399
def __next__(self) -> object:

0 commit comments

Comments
 (0)