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