Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5af105e

Browse files
committed
Make sure the docstring is always entered as the first element in the
consts, even if it is None. Simplify _lookupName() by removing lots of redundant tests.
1 parent ceccc3c commit 5af105e

2 files changed

Lines changed: 2 additions & 22 deletions

File tree

Lib/compiler/pyassem.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ def __init__(self, name, filename, args=(), optimized=0):
254254

255255
def setDocstring(self, doc):
256256
self.docstring = doc
257-
self.consts.insert(0, doc)
258257

259258
def setFlag(self, flag):
260259
self.flags = self.flags | flag
@@ -335,6 +334,7 @@ def flattenGraph(self):
335334
def convertArgs(self):
336335
"""Convert arguments from symbolic to concrete form"""
337336
assert self.stage == FLAT
337+
self.consts.insert(0, self.docstring)
338338
for i in range(len(self.insts)):
339339
t = self.insts[i]
340340
if len(t) == 2:
@@ -347,21 +347,11 @@ def convertArgs(self):
347347

348348
def _lookupName(self, name, list):
349349
"""Return index of name in list, appending if necessary"""
350-
found = None
351350
t = type(name)
352351
for i in range(len(list)):
353352
# must do a comparison on type first to prevent UnicodeErrors
354353
if t == type(list[i]) and list[i] == name:
355-
found = 1
356-
break
357-
if found:
358-
# this is cheap, but incorrect in some cases, e.g 2 vs. 2L
359-
if type(name) == type(list[i]):
360354
return i
361-
for i in range(len(list)):
362-
elt = list[i]
363-
if type(elt) == type(name) and elt == name:
364-
return i
365355
end = len(list)
366356
list.append(name)
367357
return end

Tools/compiler/compiler/pyassem.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ def __init__(self, name, filename, args=(), optimized=0):
254254

255255
def setDocstring(self, doc):
256256
self.docstring = doc
257-
self.consts.insert(0, doc)
258257

259258
def setFlag(self, flag):
260259
self.flags = self.flags | flag
@@ -335,6 +334,7 @@ def flattenGraph(self):
335334
def convertArgs(self):
336335
"""Convert arguments from symbolic to concrete form"""
337336
assert self.stage == FLAT
337+
self.consts.insert(0, self.docstring)
338338
for i in range(len(self.insts)):
339339
t = self.insts[i]
340340
if len(t) == 2:
@@ -347,21 +347,11 @@ def convertArgs(self):
347347

348348
def _lookupName(self, name, list):
349349
"""Return index of name in list, appending if necessary"""
350-
found = None
351350
t = type(name)
352351
for i in range(len(list)):
353352
# must do a comparison on type first to prevent UnicodeErrors
354353
if t == type(list[i]) and list[i] == name:
355-
found = 1
356-
break
357-
if found:
358-
# this is cheap, but incorrect in some cases, e.g 2 vs. 2L
359-
if type(name) == type(list[i]):
360354
return i
361-
for i in range(len(list)):
362-
elt = list[i]
363-
if type(elt) == type(name) and elt == name:
364-
return i
365355
end = len(list)
366356
list.append(name)
367357
return end

0 commit comments

Comments
 (0)