From 930ee51b8fe1d7764a4c643fa1d987f2569479b2 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 22 Mar 2021 21:11:36 +0100 Subject: [PATCH] tools: spiffsgen.py: avoid reallocating byte array for each new block On large filesystems (~15 MB), this reduces execution time from 11s to 0.3s. --- components/spiffs/spiffsgen.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/components/spiffs/spiffsgen.py b/components/spiffs/spiffsgen.py index a93c3465cc..d308310eaf 100755 --- a/components/spiffs/spiffsgen.py +++ b/components/spiffs/spiffsgen.py @@ -448,19 +448,21 @@ class SpiffsFS(): def to_binary(self): img = b'' + all_blocks = [] for block in self.blocks: - img += block.to_binary(self.blocks_lim) + all_blocks.append(block.to_binary(self.blocks_lim)) bix = len(self.blocks) if self.build_config.use_magic: # Create empty blocks with magic numbers while self.remaining_blocks > 0: block = SpiffsBlock(bix, self.blocks_lim, self.build_config) - img += block.to_binary(self.blocks_lim) + all_blocks.append(block.to_binary(self.blocks_lim)) self.remaining_blocks -= 1 bix += 1 else: # Just fill remaining spaces FF's - img += '\xFF' * (self.img_size - len(img)) + all_blocks.append(b'\xFF' * (self.img_size - len(img))) + img += b''.join([blk for blk in all_blocks]) return img