From 3d4e6884d8091736a4e477b3d2e4e470939b1b03 Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 3 Apr 2012 16:48:55 +0400 Subject: [PATCH] (vfs_url_split): optimized to get rid of multiple string length caclulation. Signed-off-by: Andrew Borodin --- lib/vfs/utilvfs.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c index 97ac6d1f4..6db577b72 100644 --- a/lib/vfs/utilvfs.c +++ b/lib/vfs/utilvfs.c @@ -230,14 +230,16 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) vfs_path_element_t *path_element; char *pcopy; + size_t pcopy_len; const char *pend; char *dir, *colon, *inner_colon, *at, *rest; path_element = g_new0 (vfs_path_element_t, 1); path_element->port = default_port; - pcopy = g_strdup (path); - pend = pcopy + strlen (pcopy); + pcopy_len = strlen (path); + pcopy = g_strndup (path, pcopy_len); + pend = pcopy + pcopy_len; dir = pcopy; if ((flags & URL_NOSLASH) == 0) @@ -249,7 +251,7 @@ vfs_url_split (const char *path, int default_port, vfs_url_flags_t flags) path_element->path = g_strdup (PATH_SEP_STR); else { - path_element->path = g_strdup (dir); + path_element->path = g_strndup (dir, pcopy_len - (size_t) (dir - pcopy)); *dir = '\0'; } }