Author: Brian Kearns <[email protected]>
Branch: numpy-newbyteorder
Changeset: r68018:fd7f87a0d522
Date: 2013-11-14 03:00 -0500
http://bitbucket.org/pypy/pypy/changeset/fd7f87a0d522/

Log:    remove copy of offsets_and_fields on RecordType

diff --git a/pypy/module/micronumpy/interp_dtype.py 
b/pypy/module/micronumpy/interp_dtype.py
--- a/pypy/module/micronumpy/interp_dtype.py
+++ b/pypy/module/micronumpy/interp_dtype.py
@@ -198,7 +198,6 @@
             self.fields = None
         else:
             self.fields = {}
-            ofs_and_items = []
             size = 0
             for key in space.listview(w_fields):
                 value = space.getitem(w_fields, key)
@@ -209,10 +208,9 @@
                 offset = space.int_w(space.getitem(value, space.wrap(1)))
                 self.fields[space.str_w(key)] = offset, dtype
 
-                ofs_and_items.append((offset, dtype.itemtype))
                 size += dtype.get_size()
 
-            self.itemtype = types.RecordType(ofs_and_items)
+            self.itemtype = types.RecordType()
             self.size = size
             self.name = "void" + str(8 * self.get_size())
 
@@ -328,7 +326,6 @@
     lst_w = space.listview(w_lst)
     fields = {}
     offset = 0
-    ofs_and_items = []
     fieldnames = []
     for w_elem in lst_w:
         size = 1
@@ -345,10 +342,9 @@
             raise OperationError(space.w_ValueError, space.wrap("two fields 
with the same name"))
         assert isinstance(subdtype, W_Dtype)
         fields[fldname] = (offset, subdtype)
-        ofs_and_items.append((offset, subdtype.itemtype))
         offset += subdtype.get_size() * size
         fieldnames.append(fldname)
-    itemtype = types.RecordType(ofs_and_items)
+    itemtype = types.RecordType()
     return W_Dtype(itemtype, NPY_VOID, NPY_VOIDLTR,
                    "void" + str(8 * offset * itemtype.get_element_size()),
                    NPY_VOIDLTR, space.gettypefor(interp_boxes.W_VoidBox),
diff --git a/pypy/module/micronumpy/types.py b/pypy/module/micronumpy/types.py
--- a/pypy/module/micronumpy/types.py
+++ b/pypy/module/micronumpy/types.py
@@ -1784,11 +1784,6 @@
 
 class RecordType(BaseType):
     T = lltype.Char
-    _immutable_fields_ = ['offsets_and_fields']
-
-    def __init__(self, offsets_and_fields):
-        BaseType.__init__(self)
-        self.offsets_and_fields = offsets_and_fields
 
     def get_element_size(self):
         return rffi.sizeof(self.T)
@@ -1807,14 +1802,14 @@
         if not space.issequence_w(w_item):
             raise OperationError(space.w_TypeError, space.wrap(
                 "expected sequence"))
-        if len(self.offsets_and_fields) != space.len_w(w_item):
+        if len(dtype.fields) != space.len_w(w_item):
             raise OperationError(space.w_ValueError, space.wrap(
                 "wrong length"))
         items_w = space.fixedview(w_item)
         arr = VoidBoxStorage(dtype.get_size(), dtype)
         for i in range(len(items_w)):
-            subdtype = dtype.fields[dtype.fieldnames[i]][1]
-            ofs, itemtype = self.offsets_and_fields[i]
+            ofs, subdtype = dtype.fields[dtype.fieldnames[i]]
+            itemtype = subdtype.itemtype
             w_item = items_w[i]
             w_box = itemtype.coerce(space, subdtype, w_item)
             itemtype.store(arr, 0, ofs, w_box)
@@ -1831,7 +1826,9 @@
         assert isinstance(box, interp_boxes.W_VoidBox)
         pieces = ["("]
         first = True
-        for ofs, tp in self.offsets_and_fields:
+        for name in box.dtype.fieldnames:
+            ofs, subdtype = box.dtype.fields[name]
+            tp = subdtype.itemtype
             if first:
                 first = False
             else:
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to