Skip to content

Commit

Permalink
stop chardetect.py reading file immediately when filetype known (#103)
Browse files Browse the repository at this point in the history
Even though the UniversalDetector would just return immediately, looping through a whole large file is still slow and unnecessary.
  • Loading branch information
jpz authored and dan-blanchard committed Apr 10, 2017
1 parent 1f1cf1c commit 2979943
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions chardet/cli/chardetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def description_of(lines, name='stdin'):
u = UniversalDetector()
for line in lines:
u.feed(line)
# shortcut out of the loop to save reading further - particularly useful if we read a BOM.
if u.done:
break
u.close()
result = u.result
if PY2:
Expand Down

0 comments on commit 2979943

Please sign in to comment.