Revision: 47109
          http://brlcad.svn.sourceforge.net/brlcad/?rev=47109&view=rev
Author:   abhi2011
Date:     2011-10-05 17:15:45 +0000 (Wed, 05 Oct 2011)
Log Message:
-----------
Got rid of the prefix_name function which was hogging memory, directly using 
bu_vls instead

Modified Paths:
--------------
    brlcad/trunk/src/libged/simulate/simulate.c
    brlcad/trunk/src/libged/simulate/simutils.c
    brlcad/trunk/src/libged/simulate/simutils.h

Modified: brlcad/trunk/src/libged/simulate/simulate.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simulate.c 2011-10-05 16:56:33 UTC (rev 
47108)
+++ brlcad/trunk/src/libged/simulate/simulate.c 2011-10-05 17:15:45 UTC (rev 
47109)
@@ -81,7 +81,6 @@
     struct directory *dp, *ndp;
     char *prefixed_name;
     char *prefix = "sim_";
-    size_t prefix_len, prefixed_name_len;
     int i;
     struct rigid_body *prev_node = NULL, *current_node;
     struct bu_vls dp_name_vls = BU_VLS_INIT_ZERO;

Modified: brlcad/trunk/src/libged/simulate/simutils.c
===================================================================
--- brlcad/trunk/src/libged/simulate/simutils.c 2011-10-05 16:56:33 UTC (rev 
47108)
+++ brlcad/trunk/src/libged/simulate/simutils.c 2011-10-05 17:15:45 UTC (rev 
47109)
@@ -325,16 +325,6 @@
 }
 
 
-char*
-prefix_name(char *prefix, char *name)
-{
-       struct bu_vls buffer_vls = BU_VLS_INIT_ZERO;
-       bu_vls_sprintf(&buffer_vls, "%s%s", prefix, name);
-
-       return bu_vls_addr(&buffer_vls);
-}
-
-
 int
 apply_color(struct ged *gedp,
            char* name,
@@ -398,13 +388,16 @@
     char *prefix = "bb_";
     char *prefix_reg = "bb_reg_";
     char *prefixed_name, *prefixed_reg_name;
+    struct bu_vls buffer1 = BU_VLS_INIT_ZERO, buffer2 = BU_VLS_INIT_ZERO;
     point_t v;
 
     /* Prepare prefixed bounding box primitive name */
-    prefixed_name = prefix_name(prefix, current_node->rb_namep);
+    bu_vls_sprintf(&buffer1, "%s%s", prefix, current_node->rb_namep);
+       prefixed_name = bu_vls_addr(&buffer1);
 
     /* Prepare prefixed bounding box region name */
-    prefixed_reg_name = prefix_name(prefix_reg, current_node->rb_namep);
+    bu_vls_sprintf(&buffer2, "%s%s", prefix_reg, current_node->rb_namep);
+       prefixed_reg_name = bu_vls_addr(&buffer2);
 
     /* Delete existing bb prim and region */
     rv = kill(gedp, prefixed_name);
@@ -423,7 +416,7 @@
 
     /* Setup the simulation result group union-ing the new objects */
     cmd_args[0] = "in";
-    cmd_args[1] = bu_strdup(prefixed_name);
+    cmd_args[1] = prefixed_name;
     cmd_args[2] = "arb8";
 
     /* Front face vertices */
@@ -510,8 +503,8 @@
     /* Add the region to the result of the sim so it will be drawn too */
     add_to_comb(gedp, sim_params->sim_comb_name, prefixed_reg_name);
 
-    bu_free(prefixed_name, "simulate : prefixed_name");
-    bu_free(prefixed_reg_name, "simulate : prefixed_reg_name");
+    bu_vls_free(&buffer1);
+    bu_vls_free(&buffer2);
 
     return GED_OK;
 
@@ -528,7 +521,10 @@
     char *prefix = "mf_";
     char *prefix_reg = "mf_reg_";
     char *prefix_normal = "normal_";
-    struct bu_vls buffer_vls = BU_VLS_INIT_ZERO;
+    struct bu_vls buffer1 = BU_VLS_INIT_ZERO,
+                         buffer2 = BU_VLS_INIT_ZERO,
+                         buffer3 = BU_VLS_INIT_ZERO,
+                         buffer4 = BU_VLS_INIT_ZERO;
     char *name;
     vect_t scaled_normal;
     point_t from, to;
@@ -542,18 +538,21 @@
        if(current_manifold->num_contacts > 0){
 
            /* Prepare prefixed bounding box primitive name */
-           bu_vls_sprintf(&buffer_vls, "%s_%s", 
current_manifold->rbA->rb_namep,
+           bu_vls_sprintf(&buffer1, "%s_%s", current_manifold->rbA->rb_namep,
                           current_manifold->rbB->rb_namep);
-           name = bu_vls_addr(&buffer_vls);
+           name = bu_vls_addr(&buffer1);
 
            /* Prepare the manifold shape name */
-           prefixed_name = prefix_name(prefix, name);
+           bu_vls_sprintf(&buffer2, "%s%s", prefix, name);
+           prefixed_name = bu_vls_addr(&buffer2);
 
            /* Prepare prefixed manifold region name */
-           prefixed_reg_name = prefix_name(prefix_reg, name);
+           bu_vls_sprintf(&buffer3, "%s%s", prefix_reg, name);
+           prefixed_reg_name = bu_vls_addr(&buffer3);
 
            /* Prepare prefixed manifold region name */
-           prefixed_normal_name = prefix_name(prefix_normal, name);
+           bu_vls_sprintf(&buffer4, "%s%s", prefix_normal, name);
+           prefixed_normal_name = bu_vls_addr(&buffer4);
 
            /* Delete existing manifold prim and region */
            rv = kill(gedp, prefixed_name);
@@ -660,6 +659,7 @@
                    bu_log("%d contacts got, no manifold drawn", 
current_manifold->num_contacts);
                    cmd_args[2] = (char *)0;
                    num_args = 2;
+                   break;
            }
 
            print_command(cmd_args, num_args);
@@ -694,14 +694,16 @@
 
            }/*  if-num_args */
 
-           bu_free(prefixed_name, "simulate : prefixed_name");
-           bu_free(prefixed_reg_name, "simulate : prefixed_reg_name");
-
        }/* if-num_contacts */
 
     } /* end for-manifold */
 
+    bu_vls_free(&buffer1);
+    bu_vls_free(&buffer2);
+    bu_vls_free(&buffer3);
+    bu_vls_free(&buffer4);
 
+
     return GED_OK;
 
 }

Modified: brlcad/trunk/src/libged/simulate/simutils.h
===================================================================
--- brlcad/trunk/src/libged/simulate/simutils.h 2011-10-05 16:56:33 UTC (rev 
47108)
+++ brlcad/trunk/src/libged/simulate/simutils.h 2011-10-05 17:15:45 UTC (rev 
47109)
@@ -78,13 +78,6 @@
 
 
 /**
- * Prefixes name with prefix and returns the combined string
- */
-char*
-prefix_name(char *prefix, char *name);
-
-
-/**
  * Deletes a prim/comb if it exists.
  *
  * TODO: lower to librt

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to