[cairo-commit] libsvg/src svg_gradient.c, 1.4, 1.5 svg_group.c, 1.25, 1.26 svg_str.c, 1.3, 1.4

Carl Worth commit at pdx.freedesktop.org
Thu Dec 23 14:00:03 PST 2004


Committed by: cworth

Update of /cvs/cairo/libsvg/src
In directory gabe:/tmp/cvs-serv23243/src

Modified Files:
	svg_gradient.c svg_group.c svg_str.c 
Log Message:

        * src/svg_str.c (_svg_str_parse_all_csv_doubles):
        * src/svg_group.c (_svg_group_add_element):
        * src/svg_gradient.c (_svg_gradient_add_stop): Grow arrays by
        doubling rather than by linear increments.


Index: svg_gradient.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_gradient.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- svg_gradient.c	12 Jul 2004 18:23:27 -0000	1.4
+++ svg_gradient.c	23 Dec 2004 22:00:01 -0000	1.5
@@ -98,8 +98,6 @@
     return SVG_STATUS_SUCCESS;
 }
 
-#define SVG_GRADIENT_STOPS_GROWTH 2
-
 svg_status_t
 _svg_gradient_add_stop (svg_gradient_t *gradient,
 			double		offset,
@@ -109,11 +107,15 @@
     svg_gradient_stop_t *new_stops, *stop;
 
     if (gradient->num_stops >= gradient->stops_size) {
-	gradient->stops_size += SVG_GRADIENT_STOPS_GROWTH;
+	int old_size = gradient->stops_size;
+	if (gradient->stops_size)
+	    gradient->stops_size *= 2;
+	else
+	    gradient->stops_size = 2; /* Any useful gradient has at least 2 */
 	new_stops = realloc (gradient->stops,
 			     gradient->stops_size * sizeof (svg_gradient_stop_t));
 	if (new_stops == NULL) {
-	    gradient->stops_size -= SVG_GRADIENT_STOPS_GROWTH;
+	    gradient->stops_size = old_size;
 	    return SVG_STATUS_NO_MEMORY;
 	}
 	gradient->stops = new_stops;

Index: svg_group.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_group.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- svg_group.c	7 May 2004 03:56:43 -0000	1.25
+++ svg_group.c	23 Dec 2004 22:00:01 -0000	1.26
@@ -22,10 +22,6 @@
 
 #include "svgint.h"
 
-/* XXX: I have no experience with SVG files to know what would make a
-   reasonable value here. */
-#define SVG_GROUP_ELEMENT_GROWTH_INC 5
-
 static svg_status_t
 _svg_group_grow_element_by (svg_group_t *group, int additional);
 
@@ -101,7 +97,8 @@
     svg_status_t status;
 
     if (group->num_elements >= group->element_size) {
-	status = _svg_group_grow_element_by(group, SVG_GROUP_ELEMENT_GROWTH_INC);
+	int additional = group->element_size ? group->element_size : 4;
+	status = _svg_group_grow_element_by(group, additional);
 	if (status)
 	    return status;
     }

Index: svg_str.c
===================================================================
RCS file: /cvs/cairo/libsvg/src/svg_str.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- svg_str.c	25 Jan 2003 19:07:34 -0000	1.3
+++ svg_str.c	23 Dec 2004 22:00:01 -0000	1.4
@@ -83,15 +83,15 @@
 svgint_status_t
 _svg_str_parse_all_csv_doubles (const char *str, double **value, int *num_values, const char **end)
 {
-    static const int growth=5;
     svgint_status_t status;
-    int size = 0;
+    int size = 5;
     *num_values = 0;
     *value = NULL;
 
     while (1) {
 	if (*num_values >= size) {
-	    size = *num_values + growth;
+	    while (*num_values >= size)
+		size *= 2;
 	    *value = realloc(*value, size * sizeof(double));
 	    if (*value == NULL)
 		status = SVG_STATUS_NO_MEMORY;




More information about the cairo-commit mailing list