Code

replace super-linear complexity stacked C stirng concatenations with O(1) append...
authormental <mental@users.sourceforge.net>
Mon, 22 May 2006 05:39:09 +0000 (05:39 +0000)
committermental <mental@users.sourceforge.net>
Mon, 22 May 2006 05:39:09 +0000 (05:39 +0000)
ChangeLog
src/extension/internal/svg.cpp

index 5331377b6dbf9f14b37a839f2a5019858ef34e2b..e7ce13d050ab1a9d3b9c25844070186ac9931c6a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2006-05-22  MenTaLguY  <mental@rydia.net>
+
+       * src/extension/internal/svg.cpp:
+
+         replace EXTREMELY inefficient (O(n^2), I think?) stacked C string
+         concatenations with appends to a std::vector, which is amortized O(1)
+
 2006-05-21  Marco Scholten  <mscholtn@xs4all.nl>
 
        * src/ui/dialog/inkscape-preferences.cpp, 
index 5f8517c3d33fcfd8905d3ec99b38d95b232b552b..ab9c59830f99df36bf2cf958884af4ec25c25e5d 100644 (file)
@@ -20,6 +20,7 @@
 #include "file.h"
 #include "extension/system.h"
 #include "extension/output.h"
+#include <vector>
 
 #ifdef WITH_GNOME_VFS
 # include <libgnomevfs/gnome-vfs.h>
@@ -106,9 +107,6 @@ _load_uri (const gchar *uri)
 {
     GnomeVFSHandle   *handle = NULL;
     GnomeVFSFileSize  bytes_read;
-    gchar             buffer[BUF_SIZE] = "";
-    gchar            *doc = NULL;
-    gchar            *new_doc = NULL;
 
         gsize bytesRead = 0;
         gsize bytesWritten = 0;
@@ -125,20 +123,14 @@ _load_uri (const gchar *uri)
         g_warning(gnome_vfs_result_to_string(result));
     }
 
+    std::vector<gchar> doc;
     while (result == GNOME_VFS_OK) {
+        gchar buffer[BUF_SIZE];
         result = gnome_vfs_read (handle, buffer, BUF_SIZE, &bytes_read);
-        buffer[bytes_read] = '\0';
-
-        if (doc == NULL) {
-            doc = g_strndup(buffer, bytes_read);
-        } else {
-            new_doc = g_strconcat(doc, buffer, NULL);
-            g_free(doc);
-            doc = new_doc;
-        }
+        doc.insert(doc.end(), buffer, buffer+bytes_read);
     }
 
-    return doc;
+    return g_strndup(&doc[0], doc.size());
 }
 #endif