瀏覽代碼

opt fixes for tasks and heapq

Joe Shochet 21 年之前
父節點
當前提交
454f8fd782
共有 3 個文件被更改,包括 26 次插入31 次删除
  1. 0 2
      direct/src/heapq/Sources.pp
  2. 4 7
      direct/src/heapq/heapq.cxx
  3. 22 22
      direct/src/task/Task.py

+ 0 - 2
direct/src/heapq/Sources.pp

@@ -5,8 +5,6 @@
 // under Windows).
 
 #define DIR_TYPE metalib
-//#define BUILDING_DLL BUILDING_DIRECT
-
 
 #define OTHER_LIBS \
   pandaexpress:m \

+ 4 - 7
direct/src/heapq/heapq.cxx

@@ -4,6 +4,9 @@
    reported to be about 20x faster. In 2.4 they reimplemented heapq in C so
    it should be comparable to this. At this time though, Python 2.4 is
    still in alpha.
+   
+   Note: This code has been bastardized to only work on Tasks temporarily.
+
 */
 
 #include <Python.h>
@@ -122,7 +125,7 @@ heapify(PyObject *self, PyObject *args) {
 static int
 _siftdown(PyObject *list, int startpos, int pos) {
     PyObject *newitem, *parent;
-    int parentpos, cmp;
+    int parentpos;
 
     newitem = PySequence_GetItem(list,pos);
 
@@ -150,11 +153,8 @@ _siftdown(PyObject *list, int startpos, int pos) {
 
         if (parentCTask->get_wake_time() <= newitemCTask->get_wake_time()) {
           break;
-        } else {
-          return -1;
         }
 
-
         Py_INCREF(parent);
         PyList_SetItem(list,pos,parent);
         pos = parentpos;
@@ -168,7 +168,6 @@ _siftup(PyObject *list, int pos) {
     PyObject *newitem, *right, *child;
     int endpos, rightpos, childpos;
     int startpos = pos;
-    int cmp;
     
     endpos = PyList_Size(list);
     newitem = PySequence_GetItem(list,pos);
@@ -202,8 +201,6 @@ _siftup(PyObject *list, int pos) {
 
             if (rightCTask->get_wake_time() <= childCTask->get_wake_time()) {
               childpos = rightpos;
-            } else {
-              return -1;
             }
         }
         child = PySequence_GetItem(list,childpos);

+ 22 - 22
direct/src/task/Task.py

@@ -86,28 +86,28 @@ class Task(CTask):
             self.pstats = None
         self.extraArgs = None
 
-    # Used for putting into the doLaterList
-    # the heapq calls __cmp__ via the rich compare function
-    def __cmp__(self, other):
-        if isinstance(other, Task):
-            if self.getWakeTime() < other.getWakeTime():
-                return -1
-            elif self.getWakeTime() > other.getWakeTime():
-                return 1
-            # If the wakeTimes happen to be the same, just
-            # sort them based on id
-            else:
-                return cmp(id(self), id(other))
-        # This is important for people doing a (task != None) and such.
-        else:
-            return cmp(id(self), id(other))
-
-    # According to the Python manual (3.3.1), if you define a cmp operator
-    # you should also define a hash operator or your objects will not be
-    # usable in dictionaries. Since no two task objects are unique, we can
-    # just return the unique id.
-    def __hash__(self):
-        return self.id
+#     # Used for putting into the doLaterList
+#     # the heapq calls __cmp__ via the rich compare function
+#     def __cmp__(self, other):
+#         if isinstance(other, Task):
+#             if self.getWakeTime() < other.getWakeTime():
+#                 return -1
+#             elif self.getWakeTime() > other.getWakeTime():
+#                 return 1
+#             # If the wakeTimes happen to be the same, just
+#             # sort them based on id
+#             else:
+#                 return cmp(id(self), id(other))
+#         # This is important for people doing a (task != None) and such.
+#         else:
+#             return cmp(id(self), id(other))
+
+#     # According to the Python manual (3.3.1), if you define a cmp operator
+#     # you should also define a hash operator or your objects will not be
+#     # usable in dictionaries. Since no two task objects are unique, we can
+#     # just return the unique id.
+#     def __hash__(self):
+#         return self.id
 
     def remove(self):
         if not self.__removed: