From e1fbf8609acb5d43cd392307787ea81038ec8835 Mon Sep 17 00:00:00 2001 From: mental Date: Mon, 22 May 2006 05:39:09 +0000 Subject: [PATCH] replace super-linear complexity stacked C stirng concatenations with O(1) append to std::vector --- ChangeLog | 7 +++++++ src/extension/internal/svg.cpp | 18 +++++------------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5331377b6..e7ce13d05 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2006-05-22 MenTaLguY + + * 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 * src/ui/dialog/inkscape-preferences.cpp, diff --git a/src/extension/internal/svg.cpp b/src/extension/internal/svg.cpp index 5f8517c3d..ab9c59830 100644 --- a/src/extension/internal/svg.cpp +++ b/src/extension/internal/svg.cpp @@ -20,6 +20,7 @@ #include "file.h" #include "extension/system.h" #include "extension/output.h" +#include #ifdef WITH_GNOME_VFS # include @@ -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 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 -- 2.30.2