[goffice] go_string_replace: don't rely of g_string_erase being sane.



commit b30a27418dc92870949e3b3c344a693854141764
Author: Morten Welinder <terra gnome org>
Date:   Thu Jul 1 09:05:25 2010 -0400

    go_string_replace: don't rely of g_string_erase being sane.

 ChangeLog                      |    5 +++++
 NEWS                           |    3 +++
 goffice/utils/go-glib-extras.c |   12 ++++++++++--
 3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index b5b5c47..8277334 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2010-07-01  Morten Welinder  <terra gnome org>
+
+	* goffice/utils/go-glib-extras.c (go_string_replace): New
+	function.
+
 2010-06-28  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/NEWS b/NEWS
index 2be8dd2..83d2b7c 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 goffice 0.8.8:
 
+Morten:
+	* Add go_string_replace function.
+
 --------------------------------------------------------------------------
 goffice 0.8.7:
 
diff --git a/goffice/utils/go-glib-extras.c b/goffice/utils/go-glib-extras.c
index 98add12..ff8cca6 100644
--- a/goffice/utils/go-glib-extras.c
+++ b/goffice/utils/go-glib-extras.c
@@ -354,8 +354,16 @@ go_string_replace (GString *target,
 	txt += cplen;
 	newlen -= cplen;
 
-	g_string_erase (target, pos, oldlen);
-	g_string_insert_len (target, pos, txt, newlen);
+	/*
+	 * At least one of oldlen and newlen is zero now.  We could call
+	 * both erase and insert unconditionally, but erase does not appear
+	 * to handle zero length efficiently.
+	 */
+
+	if (oldlen > 0)
+		g_string_erase (target, pos, oldlen);
+	else if (newlen > 0)
+		g_string_insert_len (target, pos, txt, newlen);
 }
 
 /* ------------------------------------------------------------------------- */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]