[pypy-commit] pypy dynamic-specialized-tuple: comments so you can understand this
noreply at buildbot.pypy.org
Wed Mar 14 08:26:54 CET 2012
Author: Alex Gaynor <alex.gaynor at gmail.com>
Date: 2012-03-14 00:26 -0700
Log: comments so you can understand this
diff --git a/pypy/rlib/rerased_raw.py b/pypy/rlib/rerased_raw.py
@@ -138,32 +138,43 @@
# XXX: This has O(n**2) complexity because of the below loop, if we could
# do more arithmetic ops on addresses then it could be O(n).
shape_addr = obj_addr + llmemory.offsetof(UNTYPEDSTORAGE, "shape")
+ # prev == NULL means it's the first item, shape is always a GC pointer,
+ # return it first
if not prev:
shape = shape_addr.address
+ # Find the length of the shape, which is also the length of data.
length_offset = (llmemory.offsetof(STR, "chars") +
length = (shape + length_offset).signed
+ # seen_prev indicates whether our loop has gone past the "prev" addr.
seen_prev = prev == shape_addr
i = 0
while i < length:
+ # This a pointer to the i-th item in data. (&obj_adr->data[i])
data_ptr = (obj_addr + llmemory.offsetof(UNTYPEDSTORAGE, "data") +
llmemory.itemoffsetof(UNTYPEDSTORAGE.data, 0) +
llmemory.sizeof(UNTYPEDSTORAGE.data.OF) * i)
+ # Check to see if we have gotten past the previous value, if we
+ # haven't, check if we're there now.
if not seen_prev:
if data_ptr == prev:
seen_prev = True
i += 1
+ # Find the i-th char in shape.
char = (shape + llmemory.offsetof(STR, "chars") +
llmemory.itemoffsetof(STR.chars, 0) +
(llmemory.sizeof(STR.chars.OF) * i)).char
+ # If it's an instance then we've found a GC pointer.
if char == INSTANCE:
i += 1
+ # If we've gotten to here, there are no GC-pointers left, return NULL to
+ # exit out.
trace_untypedstorage_ptr = llhelper(lltype.Ptr(CUSTOMTRACEFUNC), trace_untypedstorage)
More information about the pypy-commit