# HG changeset patch
# User Robert L. Miller <rlm@rlmiller.org>
# Date 1218045593 25200
# Node ID a3565e4f0f9ba13547775e64edaa16dbf441bd0d
# Parent  b1de815b82dd2e5fc79e9ef0cf70700d2cb5957c
a few optimizations/fixes

diff -r b1de815b82dd -r a3565e4f0f9b sage/groups/perm_gps/partn_ref/refinement_graphs.pxd
--- a/sage/groups/perm_gps/partn_ref/refinement_graphs.pxd	Wed Aug 06 10:36:27 2008 -0700
+++ b/sage/groups/perm_gps/partn_ref/refinement_graphs.pxd	Wed Aug 06 10:59:53 2008 -0700
@@ -24,8 +24,8 @@ cdef int refine_by_degree(PartitionStack
 cdef int refine_by_degree(PartitionStack *, object, int *, int)
 cdef int compare_graphs(int *, int *, object)
 cdef bint all_children_are_equivalent(PartitionStack *, object)
-cdef int degree(PartitionStack *, CGraph, int, int, bint)
-cdef int sort_by_function(PartitionStack *, int, int *)
+cdef inline int degree(PartitionStack *, CGraph, int, int, bint)
+cdef inline int sort_by_function(PartitionStack *, int, int *)
 
 
 
diff -r b1de815b82dd -r a3565e4f0f9b sage/groups/perm_gps/partn_ref/refinement_graphs.pyx
--- a/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx	Wed Aug 06 10:36:27 2008 -0700
+++ b/sage/groups/perm_gps/partn_ref/refinement_graphs.pyx	Wed Aug 06 10:59:53 2008 -0700
@@ -239,6 +239,9 @@ def search_tree(G_in, partition, lab=Tru
     for i from 0 <= i < len(partition):
         part[i] = <int *> sage_malloc((len(partition[i])+1) * sizeof(int))
         if part[i] is NULL:
+            for j from 0 <= j < i:
+                sage_free(part[j])
+            sage_free(part)
             raise MemoryError
         for j from 0 <= j < len(partition[i]):
             part[i][j] = partition[i][j]
@@ -251,6 +254,9 @@ def search_tree(G_in, partition, lab=Tru
     GS.use_indicator = 1 if use_indicator_function else 0
     GS.scratch = <int *> sage_malloc( (3*G.num_verts + 1) * sizeof(int) )
     if GS.scratch is NULL:
+        for j from 0 <= j < len(partition):
+            sage_free(part[j])
+        sage_free(part)
         raise MemoryError
 
     output = traverse_tree(GS, part, G.num_verts, &all_children_are_equivalent, &refine_by_degree, &compare_graphs, lab, base, order)
@@ -360,13 +366,11 @@ cdef int refine_by_degree(PartitionStack
                         cells_to_refine_by[against_index] = first_largest_subcell
                         break
                     against_index += 1
-                against_index = ctrb_len
                 r = current_cell
                 while 1:
                     if r == current_cell or PS.levels[r-1] == PS.depth:
                         if r != first_largest_subcell:
-                            cells_to_refine_by[against_index] = r
-                            against_index += 1
+                            cells_to_refine_by[ctrb_len] = r
                             ctrb_len += 1
                     r += 1
                     if r >= i:
@@ -473,7 +477,7 @@ cdef bint all_children_are_equivalent(Pa
         return 1
     return 0
 
-cdef int degree(PartitionStack *PS, CGraph G, int entry, int cell_index, bint reverse):
+cdef inline int degree(PartitionStack *PS, CGraph G, int entry, int cell_index, bint reverse):
     """
     Returns the number of edges from the vertex corresponding to entry to
     vertices in the cell corresponding to cell_index.
@@ -506,7 +510,7 @@ cdef int degree(PartitionStack *PS, CGra
                 break
     return num_arcs
 
-cdef int sort_by_function(PartitionStack *PS, int start, int *degrees):
+cdef inline int sort_by_function(PartitionStack *PS, int start, int *degrees):
     """
     A simple counting sort, given the degrees of vertices to a certain cell.
     
@@ -517,7 +521,7 @@ cdef int sort_by_function(PartitionStack
 
     """
     cdef int n = PS.degree
-    cdef int i, j, m = 2*n, max, max_location
+    cdef int i, j, max, max_location
     cdef int *counts = degrees + n, *output = degrees + 2*n + 1
     for i from 0 <= i <= n:
         counts[i] = 0
