use dict lookup for fields
This commit is contained in:
@@ -259,7 +259,9 @@ class BlendFile:
|
||||
else:
|
||||
dna_size = dna_type.size * dna_name.array_size
|
||||
|
||||
dna_struct.fields.append(DNAField(dna_type, dna_name, dna_size, dna_offset))
|
||||
field = DNAField(dna_type, dna_name, dna_size, dna_offset)
|
||||
dna_struct.fields.append(field)
|
||||
dna_struct.field_from_name[dna_name.name_only] = field
|
||||
dna_offset += dna_size
|
||||
|
||||
return structs, sdna_index_from_id
|
||||
@@ -564,17 +566,13 @@ class DNAStruct:
|
||||
"dna_type_id",
|
||||
"size",
|
||||
"fields",
|
||||
"field_from_name",
|
||||
)
|
||||
|
||||
def __init__(self, dna_type_id):
|
||||
self.dna_type_id = dna_type_id
|
||||
self.fields = []
|
||||
|
||||
def field_from_name(self, name):
|
||||
for field in self.fields:
|
||||
dna_name = field.dna_name
|
||||
if dna_name.name_only == name:
|
||||
return field
|
||||
self.field_from_name = {}
|
||||
|
||||
def field_from_path(self, header, handle, path):
|
||||
assert(type(path) == bytes)
|
||||
@@ -590,7 +588,7 @@ class DNAStruct:
|
||||
else:
|
||||
index = 0
|
||||
|
||||
field = self.field_from_name(name)
|
||||
field = self.field_from_name.get(name)
|
||||
|
||||
if field is not None:
|
||||
handle.seek(field.dna_offset, os.SEEK_CUR)
|
||||
|
@@ -18,8 +18,8 @@
|
||||
#
|
||||
# ***** END GPL LICENCE BLOCK *****
|
||||
|
||||
VERBOSE = True
|
||||
|
||||
VERBOSE = False
|
||||
TIMEIT = True
|
||||
|
||||
class FilePath:
|
||||
"""
|
||||
@@ -93,6 +93,10 @@ class FilePath:
|
||||
expand_codes = set()
|
||||
|
||||
def expand_codes_add_test(block):
|
||||
# we could investigate a better way...
|
||||
# Not to be accessing ID blocks at this point. but its harmless
|
||||
if block.code == b'ID':
|
||||
return False
|
||||
len_prev = len(expand_codes)
|
||||
expand_codes.add(block[b'id.name'])
|
||||
return (len_prev != len(expand_codes))
|
||||
@@ -152,7 +156,9 @@ class FilePath:
|
||||
|
||||
continue
|
||||
|
||||
print(" Scanning", code)
|
||||
if VERBOSE:
|
||||
print(" Scanning", code)
|
||||
|
||||
for block in iter_blocks_id(code):
|
||||
yield from FilePath.from_block(block, basedir, rootdir, level)
|
||||
|
||||
@@ -287,7 +293,7 @@ class ExpandID:
|
||||
|
||||
@staticmethod
|
||||
def _expand_generic_mtex(block):
|
||||
field = block.dna_type.field_from_name(b'mtex')
|
||||
field = block.dna_type.field_from_name[b'mtex']
|
||||
array_len = field.dna_size // block.file.header.pointer_size
|
||||
|
||||
for i in range(array_len):
|
||||
@@ -392,6 +398,10 @@ def pack(blendfile_src, blendfile_dst):
|
||||
|
||||
SUBDIR = b'data'
|
||||
|
||||
if TIMEIT:
|
||||
import time
|
||||
t = time.time()
|
||||
|
||||
def temp_remap_cb(filepath, level):
|
||||
"""
|
||||
Create temp files in the destination path.
|
||||
@@ -460,6 +470,9 @@ def pack(blendfile_src, blendfile_dst):
|
||||
|
||||
print(" Written:", blendfile_dst)
|
||||
|
||||
if TIMEIT:
|
||||
print(" Time: %.4f" % (time.time() - t))
|
||||
|
||||
|
||||
def create_argparse():
|
||||
import os
|
||||
|
Reference in New Issue
Block a user