From 59e5ef7b52e177fd55110a6d1fa169007fe63f5c Mon Sep 17 00:00:00 2001 From: "peterl%netscape.com" Date: Fri, 7 Aug 1998 02:11:13 +0000 Subject: [PATCH] performance tweak in trim --- base/src/nsString.cpp | 9 +++++++-- string/obsolete/nsString.cpp | 9 +++++++-- xpcom/ds/nsString.cpp | 9 +++++++-- xpcom/string/obsolete/nsString.cpp | 9 +++++++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/base/src/nsString.cpp b/base/src/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/base/src/nsString.cpp +++ b/base/src/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0'; diff --git a/string/obsolete/nsString.cpp b/string/obsolete/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/string/obsolete/nsString.cpp +++ b/string/obsolete/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0'; diff --git a/xpcom/ds/nsString.cpp b/xpcom/ds/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/xpcom/ds/nsString.cpp +++ b/xpcom/ds/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0'; diff --git a/xpcom/string/obsolete/nsString.cpp b/xpcom/string/obsolete/nsString.cpp index 39105ea33c5..04c90dedd62 100644 --- a/xpcom/string/obsolete/nsString.cpp +++ b/xpcom/string/obsolete/nsString.cpp @@ -1118,8 +1118,13 @@ nsString& nsString::Trim(const char* aTrimSet, //now rewrite your string without unwanted //leading or trailing characters. - while (from <= end) { - *to++ = *from++; + if (from != to) { + while (from <= end) { + *to++ = *from++; + } + } + else { + to = ++end; } *to = '\0';