From 5c3b79c8e09dd85f992332cfbfa556790d3e456e Mon Sep 17 00:00:00 2001 From: amosjeffries <> Date: Wed, 23 Jan 2008 10:06:20 +0000 Subject: [PATCH] Reduce call duplication in String. - Removes duplicate clean() calls - Pushes clean() calls as far down the stack as possible on each init* - Removes small memory leak in limitInit() --- src/String.cc | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/String.cc b/src/String.cc index 5fa2e5c3a5..9da75947b7 100644 --- a/src/String.cc +++ b/src/String.cc @@ -1,6 +1,6 @@ /* - * $Id: String.cc,v 1.26 2007/05/29 13:31:38 amosjeffries Exp $ + * $Id: String.cc,v 1.27 2008/01/23 03:06:20 amosjeffries Exp $ * * DEBUG: section 67 String * AUTHOR: Duane Wessels @@ -40,6 +40,7 @@ void String::initBuf(size_t sz) { PROF_start(StringInitBuf); + clean(); buf((char *)memAllocString(sz, &sz)); assert(sz < 65536); size_ = sz; @@ -71,8 +72,7 @@ String::String (char const *aString) : size_(0), len_(0), buf_(NULL) String & String::operator =(char const *aString) { - clean(); - init (aString); + init(aString); return *this; } @@ -81,8 +81,8 @@ String::operator = (String const &old) { clean (); - if (old.len_) - limitInit (old.buf(), old.len_); + if(old.size() > 0) + limitInit(old.buf(), old.size()); return *this; } @@ -119,7 +119,7 @@ String::limitInit(const char *str, int len) String::String (String const &old) : size_(0), len_(0), buf_(NULL) { - init (old.buf()); + limitInit(old.buf(), old.size()); #if DEBUGSTRINGS StringRegistry::Instance().add(this); @@ -156,7 +156,6 @@ void String::reset(const char *str) { PROF_start(StringReset); - clean(); init(str); PROF_stop(StringReset); } -- 2.47.3