Microoptimizations; minor fix

The microoptimizations do nothing at all, but it was poor style before them.

The fix is a missing u for a Unicode string.
This commit is contained in:
Sei Lisa 2023-01-31 20:41:37 +01:00
parent 8e20a06912
commit 91b3186245
2 changed files with 7 additions and 4 deletions

View file

@ -552,7 +552,7 @@ def InternalTypecast(val, out, InList, f32):
if out in (Vector, Quaternion): if out in (Vector, Quaternion):
Z,dim = (ZERO_VECTOR,3) if out == Vector else (ZERO_ROTATION,4) Z,dim = (ZERO_VECTOR,3) if out == Vector else (ZERO_ROTATION,4)
ret = [] ret = []
if val[0:1] != u'<': if not val.startswith(u'<'):
return Z return Z
val = val[1:] val = val[1:]
for _ in range(dim): for _ in range(dim):
@ -562,7 +562,8 @@ def InternalTypecast(val, out, InList, f32):
if match.group(1): if match.group(1):
ret.append(F32(float.fromhex(match.group(0)), f32)) ret.append(F32(float.fromhex(match.group(0)), f32))
elif match.group(2): elif match.group(2):
ret.append(Indet if match.group(0)[0] == '-' else NaN) ret.append(Indet if match.group(0).startswith(u'-') else
NaN)
else: else:
ret.append(F32(float(match.group(0)), f32)) ret.append(F32(float(match.group(0)), f32))
if len(ret) < dim: if len(ret) < dim:

View file

@ -175,7 +175,8 @@ def LoadLibrary(builtins = None, fndata = None):
value = None value = None
elif typ in (u'vector', u'rotation'): elif typ in (u'vector', u'rotation'):
try: try:
if value[0:1] != u'<' or value[-1:] != u'>': if not (value.startswith(u'<') and value.endswith(u'>')
):
raise ValueError raise ValueError
value = value[1:-1].split(u',') value = value[1:-1].split(u',')
if len(value) != (3 if typ == 'vector' else 4): if len(value) != (3 if typ == 'vector' else 4):
@ -205,7 +206,8 @@ def LoadLibrary(builtins = None, fndata = None):
u" line %d: %s" % (ubuiltins, linenum, line)) u" line %d: %s" % (ubuiltins, linenum, line))
else: else:
assert typ == u'list' assert typ == u'list'
if value[0:1] != u'[' or value[-1:] != u']': if not (value.startswith(u'[') and value.endswith(u']')
):
warning(u"Invalid list value in %s, line %d: %s" warning(u"Invalid list value in %s, line %d: %s"
% (ubuiltins, linenum, line)) % (ubuiltins, linenum, line))
elif value[1:-1].strip() != '': elif value[1:-1].strip() != '':