mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-04 21:24:32 +02:00
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.
This commit is contained in:
@@ -448,19 +448,21 @@ class SpiffsFS():
|
|||||||
|
|
||||||
def to_binary(self):
|
def to_binary(self):
|
||||||
img = b''
|
img = b''
|
||||||
|
all_blocks = []
|
||||||
for block in self.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)
|
bix = len(self.blocks)
|
||||||
if self.build_config.use_magic:
|
if self.build_config.use_magic:
|
||||||
# Create empty blocks with magic numbers
|
# Create empty blocks with magic numbers
|
||||||
while self.remaining_blocks > 0:
|
while self.remaining_blocks > 0:
|
||||||
block = SpiffsBlock(bix, self.blocks_lim, self.build_config)
|
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
|
self.remaining_blocks -= 1
|
||||||
bix += 1
|
bix += 1
|
||||||
else:
|
else:
|
||||||
# Just fill remaining spaces FF's
|
# 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
|
return img
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user