Code

get rid of sp_curve_new_from_static_bpath() in a bid to simplify curve memory management
authormental <mental@users.sourceforge.net>
Tue, 9 May 2006 04:12:54 +0000 (04:12 +0000)
committermental <mental@users.sourceforge.net>
Tue, 9 May 2006 04:12:54 +0000 (04:12 +0000)
ChangeLog
src/display/curve.cpp
src/display/curve.h
src/dropper-context.cpp

index fc04c8467101f20329433d741bdaf874fc659aa9..a23a46842541f7bc8000fd037815fc028fe50007 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-05-08  MenTaLguY  <mental@rydia.net>
+
+       * src/display/curve.h, src/display/curve.cpp, src/dropper-context.cpp:
+
+         get rid of sp_curve_new_from_static_bpath() in a bid to simplify curve
+         memory management
+
 2006-05-08  MenTaLguY  <mental@rydia.net>
 
        * src/display/canvas-bpath.cpp, src/display/curve.cpp, src/display/curve.h,
index 3ea4e60dfd7756fa51b65a2256805a21d906d952..aa899b902b64d161ee3585bfafcafa3f66345086 100644 (file)
@@ -61,7 +61,6 @@ sp_curve_new_sized(gint length)
     curve->end = 0;
     curve->length = length;
     curve->substart = 0;
-    curve->sbpath = false;
     curve->hascpt = false;
     curve->posSet = false;
     curve->moving = false;
@@ -101,49 +100,6 @@ sp_curve_new_from_bpath(NArtBpath *bpath)
             (curve->_bpath[i].code == NR_MOVETO_OPEN))
             break;
     curve->substart = i;
-    curve->sbpath = false;
-    curve->hascpt = false;
-    curve->posSet = false;
-    curve->moving = false;
-    curve->closed = sp_bpath_closed(bpath);
-
-    return curve;
-}
-
-/** 
- * Construct an SPCurve from read-only, static storage.
- *
- *  We could treat read-onliness and staticness (i.e. can't call free on bpath) as orthogonal
- *  attributes, but at the time of writing we have only one caller.
- */
-SPCurve *
-sp_curve_new_from_static_bpath(NArtBpath const *bpath)
-{
-    g_return_val_if_fail(bpath != NULL, NULL);
-
-    bool sbpath;
-    if (!sp_bpath_good(bpath)) {
-        NArtBpath *new_bpath = sp_bpath_clean(bpath);
-        g_return_val_if_fail(new_bpath != NULL, NULL);
-        sbpath = false;
-        bpath = new_bpath;
-    } else {
-        sbpath = true;
-    }
-
-    SPCurve *curve = g_new(SPCurve, 1);
-
-    curve->refcount = 1;
-    curve->_bpath = const_cast<NArtBpath *>(bpath);
-    curve->length = sp_bpath_length(bpath);
-    curve->end = curve->length - 1;
-    gint i = curve->end;
-    for (; i > 0; i--)
-        if ((curve->_bpath[i].code == NR_MOVETO) ||
-            (curve->_bpath[i].code == NR_MOVETO_OPEN))
-            break;
-    curve->substart = i;
-    curve->sbpath = sbpath;
     curve->hascpt = false;
     curve->posSet = false;
     curve->moving = false;
@@ -207,7 +163,7 @@ sp_curve_unref(SPCurve *curve)
     curve->refcount -= 1;
 
     if (curve->refcount < 1) {
-        if ((!curve->sbpath) && (curve->_bpath)) {
+        if (curve->_bpath) {
             nr_free(curve->_bpath);
         }
         g_free(curve);
@@ -330,7 +286,6 @@ static void
 tmpl_curve_transform(SPCurve *const curve, M const &m)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
 
     for (gint i = 0; i < curve->end; i++) {
         NArtBpath *p = curve->_bpath + i;
@@ -381,7 +336,6 @@ void
 sp_curve_reset(SPCurve *curve)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
 
     curve->_bpath->code = NR_END;
     curve->end = 0;
@@ -410,7 +364,6 @@ void
 sp_curve_moveto(SPCurve *curve, NR::Point const &p)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
     g_return_if_fail(!curve->moving);
 
     curve->substart = curve->end;
@@ -435,7 +388,6 @@ void
 sp_curve_lineto(SPCurve *curve, gdouble x, gdouble y)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
     g_return_if_fail(curve->hascpt);
 
     if (curve->moving) {
@@ -486,7 +438,6 @@ void
 sp_curve_lineto_moving(SPCurve *curve, gdouble x, gdouble y)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
     g_return_if_fail(curve->hascpt);
 
     if (curve->moving) {
@@ -554,7 +505,6 @@ void
 sp_curve_curveto(SPCurve *curve, gdouble x0, gdouble y0, gdouble x1, gdouble y1, gdouble x2, gdouble y2)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
     g_return_if_fail(curve->hascpt);
     g_return_if_fail(!curve->moving);
 
@@ -604,7 +554,6 @@ void
 sp_curve_closepath(SPCurve *curve)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
     g_return_if_fail(curve->hascpt);
     g_return_if_fail(!curve->posSet);
     g_return_if_fail(!curve->moving);
@@ -648,7 +597,6 @@ void
 sp_curve_closepath_current(SPCurve *curve)
 {
     g_return_if_fail(curve != NULL);
-    g_return_if_fail(!curve->sbpath);
     g_return_if_fail(curve->hascpt);
     g_return_if_fail(!curve->posSet);
     g_return_if_fail(!curve->closed);
index 07d951b6330022ddccfd3ee732fdfbe3d7db4fbe..5be8f5a4e48497157556b898acfc9489cca97e34 100644 (file)
@@ -45,11 +45,6 @@ struct SPCurve {
     /// (first subitem of the item about zero-length path segments)
     NR::Point movePos;
 
-    /// True iff bpath points to read-only, static storage (see callers of
-    /// sp_curve_new_from_static_bpath), in which case we shouldn't free 
-    /// bpath and shouldn't write through it.
-    bool sbpath : 1;
-    
     /// True iff current point is defined.  Initially false for a new curve; 
     /// becomes true after moveto; becomes false on closepath.  Curveto, 
     /// lineto etc. require hascpt; hascpt remains true after lineto/curveto.
@@ -74,7 +69,6 @@ struct SPCurve {
 SPCurve *sp_curve_new();
 SPCurve *sp_curve_new_sized(gint length);
 SPCurve *sp_curve_new_from_bpath(NArtBpath *bpath);
-SPCurve *sp_curve_new_from_static_bpath(NArtBpath const *bpath);
 SPCurve *sp_curve_new_from_foreign_bpath(NArtBpath const bpath[]);
 
 SPCurve *sp_curve_ref(SPCurve *curve);
index 148cceda47b0bef2a0b4a93b0a4aa87d07d1ef3c..0e621c32551f8ace68d14091411903c09148dc9e 100644 (file)
@@ -111,7 +111,7 @@ static void sp_dropper_context_setup(SPEventContext *ec)
         ((SPEventContextClass *) parent_class)->setup(ec);
     }
 
-    SPCurve *c = sp_curve_new_from_static_bpath(spdc_circle);
+    SPCurve *c = sp_curve_new_from_foreign_bpath(spdc_circle);
     dc->area = sp_canvas_bpath_new(sp_desktop_controls(ec->desktop), c);
     sp_curve_unref(c);
     sp_canvas_bpath_set_fill(SP_CANVAS_BPATH(dc->area), 0x00000000,(SPWindRule)0);