Browse Source

opt fixes for tasks and heapq

Joe Shochet 21 years ago
parent
commit
454f8fd782
3 changed files with 26 additions and 31 deletions
  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).
 // under Windows).
 
 
 #define DIR_TYPE metalib
 #define DIR_TYPE metalib
-//#define BUILDING_DLL BUILDING_DIRECT
-
 
 
 #define OTHER_LIBS \
 #define OTHER_LIBS \
   pandaexpress:m \
   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
    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
    it should be comparable to this. At this time though, Python 2.4 is
    still in alpha.
    still in alpha.
+   
+   Note: This code has been bastardized to only work on Tasks temporarily.
+
 */
 */
 
 
 #include <Python.h>
 #include <Python.h>
@@ -122,7 +125,7 @@ heapify(PyObject *self, PyObject *args) {
 static int
 static int
 _siftdown(PyObject *list, int startpos, int pos) {
 _siftdown(PyObject *list, int startpos, int pos) {
     PyObject *newitem, *parent;
     PyObject *newitem, *parent;
-    int parentpos, cmp;
+    int parentpos;
 
 
     newitem = PySequence_GetItem(list,pos);
     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()) {
         if (parentCTask->get_wake_time() <= newitemCTask->get_wake_time()) {
           break;
           break;
-        } else {
-          return -1;
         }
         }
 
 
-
         Py_INCREF(parent);
         Py_INCREF(parent);
         PyList_SetItem(list,pos,parent);
         PyList_SetItem(list,pos,parent);
         pos = parentpos;
         pos = parentpos;
@@ -168,7 +168,6 @@ _siftup(PyObject *list, int pos) {
     PyObject *newitem, *right, *child;
     PyObject *newitem, *right, *child;
     int endpos, rightpos, childpos;
     int endpos, rightpos, childpos;
     int startpos = pos;
     int startpos = pos;
-    int cmp;
     
     
     endpos = PyList_Size(list);
     endpos = PyList_Size(list);
     newitem = PySequence_GetItem(list,pos);
     newitem = PySequence_GetItem(list,pos);
@@ -202,8 +201,6 @@ _siftup(PyObject *list, int pos) {
 
 
             if (rightCTask->get_wake_time() <= childCTask->get_wake_time()) {
             if (rightCTask->get_wake_time() <= childCTask->get_wake_time()) {
               childpos = rightpos;
               childpos = rightpos;
-            } else {
-              return -1;
             }
             }
         }
         }
         child = PySequence_GetItem(list,childpos);
         child = PySequence_GetItem(list,childpos);

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

@@ -86,28 +86,28 @@ class Task(CTask):
             self.pstats = None
             self.pstats = None
         self.extraArgs = 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):
     def remove(self):
         if not self.__removed:
         if not self.__removed: