1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-02 09:12:40 +01:00

[jsinterp] Avoid double key lookup for setting new key

In order to add a new key to both __objects and __functions dicts on jsinterp.py, it is
necessary to first verify if a key was present and if not, create the key and
assign it to a value.

However, this can be done with a single step using dict setdefault method.
This commit is contained in:
Lucas Moura 2016-06-18 17:01:47 -03:00 committed by Sergey M․
parent 589568789f
commit 7c05097633
No known key found for this signature in database
GPG Key ID: 2C393E0F18A9236D

View File

@ -131,9 +131,8 @@ def interpret_expression(self, expr, local_vars, allow_recursion):
if variable in local_vars: if variable in local_vars:
obj = local_vars[variable] obj = local_vars[variable]
else: else:
if variable not in self._objects: obj = self._objects.setdefault(
self._objects[variable] = self.extract_object(variable) variable, self.extract_object(variable))
obj = self._objects[variable]
if arg_str is None: if arg_str is None:
# Member access # Member access
@ -204,8 +203,7 @@ def interpret_expression(self, expr, local_vars, allow_recursion):
argvals = tuple([ argvals = tuple([
int(v) if v.isdigit() else local_vars[v] int(v) if v.isdigit() else local_vars[v]
for v in m.group('args').split(',')]) for v in m.group('args').split(',')])
if fname not in self._functions: self._functions.setdefault(fname, self.extract_function(fname))
self._functions[fname] = self.extract_function(fname)
return self._functions[fname](argvals) return self._functions[fname](argvals)
raise ExtractorError('Unsupported JS expression %r' % expr) raise ExtractorError('Unsupported JS expression %r' % expr)