From 891a8759902e5871055a48fd9e7c4067a4917614 Mon Sep 17 00:00:00 2001 From: glubsy Date: Fri, 13 Aug 2021 21:33:21 +0200 Subject: [PATCH] Cache constant expression Perhaps the python byte code is already optimized, but just in case it is not, keep pre-compute the constant expression. --- core/fs.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/core/fs.py b/core/fs.py index 9fc89cfb..abb8c3fc 100644 --- a/core/fs.py +++ b/core/fs.py @@ -36,6 +36,8 @@ NOT_SET = object() # CPU. CHUNK_SIZE = 1024 * 1024 # 1 MiB +# Minimum size below which partial hashes don't need to be computed +MIN_FILE_SIZE = 3 * CHUNK_SIZE # 3MiB, because we take 3 samples class FSError(Exception): cls_message = "An error has occured on '{name}' in '{parent}'" @@ -153,7 +155,7 @@ class File: with self.path.open("rb") as fp: size = self.size # Might as well hash such small files entirely. - if size <= CHUNK_SIZE * 3: # 3MiB, because 3 samples + if size <= MIN_FILE_SIZE: setattr(self, field, self.md5) return