[pypy-svn] r39870 - pypy/dist/pypy/doc/discussion
hpk at codespeak.net
hpk at codespeak.net
Sun Mar 4 12:52:06 CET 2007
Author: hpk
Date: Sun Mar 4 12:52:03 2007
New Revision: 39870
Modified:
pypy/dist/pypy/doc/discussion/chained_getattr.txt
Log:
(Anto, hpk) updates, rather use a dict at module global level,
and tweak the current code consideations a bit
Modified: pypy/dist/pypy/doc/discussion/chained_getattr.txt
==============================================================================
--- pypy/dist/pypy/doc/discussion/chained_getattr.txt (original)
+++ pypy/dist/pypy/doc/discussion/chained_getattr.txt Sun Mar 4 12:52:03 2007
@@ -26,31 +26,41 @@
now for the LOAD_CHAINED_GLOBAL bytecode implementation:
Module dicts have a special implemnetation, providing:
- - an extra "fastlookup" rpython-list serving as a cache for
- LOAD_CHAINED_GLOBAL places within the modules
- - LOAD_CHAINED_GLOBAL has an index pointing into the
- rpython-list
- - the fastlookup list contains e.g. tuple entries:
- ([obj1, obj2, obj3], [verglobals, ver1, ver2])
- "verglobals" refers to the version of the module globals
- at which the initial 'os' global lookup was done.
+ - an extra "fastlookup" rpython-dict serving as a cache for
+ LOAD_CHAINED_GLOBAL places within the modules:
+ - keys are e.g. ('os', 'path', 'normpath')
+ - values are tuples of the form:
+ ([obj1, obj2, obj3], [ver1, ver2])
"ver1" refer to the version of the globals of "os"
"ver2" refer to the version of the globals of "os.path"
"obj3" is the resulting "normpath" function
+ - upon changes to the global dict, "fastlookup.clear()" is called
+
- after the fastlookup entry is filled for a given
LOAD_CHAINED_GLOBAL index, the following checks need
to be performed in the bytecode implementation:
- objects, versions = f_globals.fastlookup[chained_global_index]
- if getver(f_globals) != versions[0]:
- return do_full_lookup()
- i = 0
- while i < len(objects) - 1:
- curobj = objects[i]
- lastversion = versions[i+1]
- currentversion = getver(curobj)
- if currentversion != lastversion:
- return do_full_lookup() # can be more clever
- i += 1
+ value = f_globals.fastlookup.get(key, None)
+ if value is None:
+ # fill entry
+ else:
+ # check that our cached lookups are still valid
+ assert isinstance(value, tuple)
+ objects, versions = value
+ i = 0
+ while i < len(versions):
+ lastversion = versions[i]
+ ver = getver_for_obj(objects[i])
+ if ver == -1 or ver != lastversion:
+ name = key[i]
+ objects[i] = space.getattr(curobj, name)
+ versions[i] = ver
+ curobj = objects[i]
+ i += 1
return objects[i]
+
+ def getver_for_obj(obj):
+ if "obj is not Module":
+ return -1
+ return obj.w_dict.version
More information about the Pypy-commit
mailing list