pep-550: Add a return (#346)
* pep-550: Add a return * pep-550: Clarify that ContextItem.get() cache uses a borrowed ref
This commit is contained in:
parent
46e3edcbb0
commit
f67bb4e465
|
@ -222,6 +222,8 @@ follows (in pseudo-code)::
|
|||
if self in local_context:
|
||||
return local_context[self]
|
||||
|
||||
return None
|
||||
|
||||
def set(self, value):
|
||||
tstate = PyThreadState_Get()
|
||||
|
||||
|
@ -838,13 +840,17 @@ The above two fields allow implementing a fast cache path in
|
|||
value = mapping[self]
|
||||
break
|
||||
|
||||
self.last_value = value
|
||||
self.last_value = value # borrowed ref
|
||||
self.last_tstate_id = tstate.unique_id
|
||||
self.last_ver = tstate.execution_context_ver
|
||||
self.last_deallocs = tstate.interp.context_item_deallocs
|
||||
|
||||
return value
|
||||
|
||||
Note that ``last_value`` is a borrowed reference. The assumption
|
||||
is that if all counters tests are OK, the object will be alive.
|
||||
This allows the CI values to be properly GCed.
|
||||
|
||||
This is similar to the trick that decimal C implementation uses
|
||||
for caching the current decimal context, and will have the same
|
||||
performance characteristics, but available to all
|
||||
|
|
Loading…
Reference in New Issue