[24063] in Source-Commits

home help back first fref pref prev next nref lref last post

/svn/athena r23667 - in trunk/athena/bin/delete: . debian

daemon@ATHENA.MIT.EDU (Evan Broder)
Sun Mar 29 15:57:07 2009

Date: Sun, 29 Mar 2009 15:56:55 -0400
From: Evan Broder <broder@MIT.EDU>
Message-Id: <200903291956.n2TJuteJ009391@drugstore.mit.edu>
To: source-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: broder
Date: 2009-03-29 15:56:55 -0400 (Sun, 29 Mar 2009)
New Revision: 23667

Modified:
   trunk/athena/bin/delete/debian/changelog
   trunk/athena/bin/delete/pattern.c
   trunk/athena/bin/delete/pattern.h
Log:
In delete:
  * Apply patches from jik:
    - When adding to an array, leave some extra space at the end so that
      we don't have to keep growing it every time.

Modified: trunk/athena/bin/delete/debian/changelog
===================================================================
--- trunk/athena/bin/delete/debian/changelog	2009-03-29 19:56:42 UTC (rev 23666)
+++ trunk/athena/bin/delete/debian/changelog	2009-03-29 19:56:55 UTC (rev 23667)
@@ -14,6 +14,8 @@
     - Change the "st_chtime" structure member to "st_ctim" to avoid a
       potential header file conflict.
     - Don't try to use symbolic links on platforms that don't have them.
+    - When adding to an array, leave some extra space at the end so that
+      we don't have to keep growing it every time.
 
  -- Evan Broder <broder@mit.edu>  Sun, 29 Mar 2009 15:07:52 -0400
 

Modified: trunk/athena/bin/delete/pattern.c
===================================================================
--- trunk/athena/bin/delete/pattern.c	2009-03-29 19:56:42 UTC (rev 23666)
+++ trunk/athena/bin/delete/pattern.c	2009-03-29 19:56:55 UTC (rev 23667)
@@ -40,16 +40,28 @@
  * lengths, merges the two into the first by realloc'ing the first and
  * then free's the second's memory usage.
  */  
-int add_arrays(array1, num1, array2, num2)
+int add_arrays(array1, num1, size1, array2, num2)
 char ***array1, ***array2;
-int *num1, *num2;
+int *num1, *size1, *num2;
 {
      int counter;
-     
+
+     if (! *size1) {
+       if (*array1)
+	 free(*array1);
+       *array1 = *array2;
+       *num1 = *num2;
+       *size1 = *num2;
+       return 0;
+     }
+
+     while (*size1 < (*num1 + *num2)) {
+       *size1 *= 2;
+     }
+
      *array1 = (char **) realloc((char *) *array1, (unsigned)
-				 (sizeof(char *) * (*num1 + *num2)));
-     if ((! *array1) && (*num1 + *num2))
-     {
+				 (sizeof(char *) * *size1));
+     if (! *array1) {
 	  set_error(errno);
 	  error("realloc");
 	  return error_code;
@@ -69,15 +81,27 @@
 /*
  * Add a string to a list of strings.
  */
-int add_str(strs, num, str)
+int add_str(strs, num, size, str)
 char ***strs;
-int num;
+int num, *size;
 char *str;
 {
      char **ary;
 
-     ary = *strs = (char **) realloc((char *) *strs, (unsigned)
-				     (sizeof(char *) * (num + 1)));
+     if (! *size) {
+       num = 0;
+       *size = 1;
+       ary = *strs = (char **) malloc((unsigned) (sizeof(char *)));
+     }
+     else if (num == *size) {
+       *size *= 2;
+       ary = *strs = (char **) realloc((char *) *strs, (unsigned)
+				       (sizeof(char *) * *size));
+     }
+     else {
+       ary = *strs;
+     }
+
      if (! *strs) {
 	  set_error(errno);
 	  error("realloc");
@@ -171,7 +195,7 @@
 {
      char 	**matched_files, **return_files, **recurs_files;
      int 	num_matched_files = 0, num_return_files = 0,
-                num_recurs_files = 0;
+                num_recurs_files = 0, return_files_size = 0;
      int	retval;
      int	i;
 #ifdef DEBUG
@@ -232,7 +256,8 @@
 
 	       if (num_recurs_files) {
 		    retval = add_arrays(&return_files, &num_return_files,
-					&recurs_files, &num_recurs_files);
+					&return_files_size, &recurs_files,
+					&num_recurs_files);
 		    if (retval) {
 			 error("add_arrays");
 			 return retval;
@@ -249,6 +274,7 @@
 	       if (is_deleted(lastpart(matched_files[i]))) {
 		    if (options & FIND_DELETED) {
 			 retval = add_str(&return_files, num_return_files,
+					  &return_files_size,
 					  matched_files[i]);
 			 if (retval) {
 			      error("add_str");
@@ -263,7 +289,7 @@
 	       }
 	       else if (options & FIND_UNDELETED) {
 		    retval = add_str(&return_files, num_return_files,
-				     matched_files[i]);
+				     &return_files_size, matched_files[i]);
 		    if (retval) {
 			 error("add_str");
 			 return retval;
@@ -406,6 +432,7 @@
 #ifdef PATTERN_DEBUG
      int j;
 #endif
+     int found_size = 0;
      
 #ifdef DEBUG
      printf("do_match: looking for %s\n", name);
@@ -435,7 +462,7 @@
      }
      (void) strcpy(first, firstpart(name, rest));
      if ((! *first) && (match_undeleted)) {
-	  retval = add_str(found, *num_found, base);
+	  retval = add_str(found, *num_found, &found_size, base);
 	  if (retval) {
 	       error("add_str");
 	       (void) popall();
@@ -511,7 +538,8 @@
 	  if (! *first) {
 	       if (is_deleted(lastpart(base))) {
 		    if (match_deleted) {
-			 retval = add_str(found, *num_found, base);
+			 retval = add_str(found, *num_found, &found_size,
+					  base);
 			 if (retval) {
 			      error("add_str");
 			      (void) popall();
@@ -524,7 +552,7 @@
 		    }
 	       }
 	       else if (match_undeleted) {
-		    retval = add_str(found, *num_found, base);
+		    retval = add_str(found, *num_found, &found_size, base);
 		    if (retval) {
 			 error("add_str");
 			 (void) popall();
@@ -745,6 +773,7 @@
      int strsize;
      struct stat statbuf;
      int use_stat;
+     int found_size = 0;
 
 #ifdef DEBUG
      fprintf(stderr, "do_recurs: opening %s\n", name);
@@ -825,7 +854,7 @@
 
 	  if (is_deleted(dp->d_name)) {
 	       if (options & FIND_DELETED) {
-		    retval = add_str(found, *num_found,
+		    retval = add_str(found, *num_found, &found_size,
 				     append(base, dp->d_name));
 		    if (retval) {
 			 error("add_str");
@@ -845,7 +874,7 @@
 	  if (options & FIND_UNDELETED) {
 	       if (is_dotfile(dp->d_name)) {
 		    if (options & FIND_DOTFILES) {
-			 retval = add_str(found, *num_found,
+			 retval = add_str(found, *num_found, &found_size,
 					  append(base, dp->d_name));
 			 if (retval) {
 			      error("add_str");
@@ -856,7 +885,7 @@
 		    continue;
 	       }
 	       else {
-		    retval = add_str(found, *num_found,
+		    retval = add_str(found, *num_found, &found_size,
 				     append(base, dp->d_name));
 		    if (retval) {
 			 error("add_str");

Modified: trunk/athena/bin/delete/pattern.h
===================================================================
--- trunk/athena/bin/delete/pattern.h	2009-03-29 19:56:42 UTC (rev 23666)
+++ trunk/athena/bin/delete/pattern.h	2009-03-29 19:56:55 UTC (rev 23667)
@@ -10,8 +10,9 @@
  */
 #include "mit-copying.h"
 
-int add_str();
-int add_arrays();
+int add_str(char ***array, int array_count, int *array_size, char *string);
+int add_arrays(char ***array1, int *num1, int *size1, char ***array2,
+	       int *num2);
 int find_contents();
 int find_deleted_contents();
 int find_deleted_contents_recurs();


home help back first fref pref prev next nref lref last post