Closed Bug 13038 Opened 25 years ago Closed 25 years ago

unexpected heap alloc in nsCAutoString::nsCAutoString(const nsStr&)

Categories

(Core :: XPCOM, defect, P3)

defect

Tracking

()

RESOLVED FIXED

People

(Reporter: waterson, Assigned: rickg)

Details

(Keywords: perf)

This method creates an unnecessary temporary because it must coerce the |const
nsStr&| to a |const nsCString&| in order to call nsCString::Append(const
nsCString&). I'd recommend either adding nsCString::Append(const nsStr&), or
replacing the call to Append with a direct call to nsStr::Assign()...

Index: nsString.cpp
===================================================================
RCS file: /cvsroot/mozilla/xpcom/ds/nsString.cpp,v
retrieving revision 3.73
diff -c -r3.73 nsString.cpp
*** nsString.cpp	1999/09/02 07:04:54	3.73
--- nsString.cpp	1999/09/02 18:13:29
***************
*** 1775,1781 ****
    mAgent=0;
    nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
    AddNullTerminator(*this);
!   Append(aString);
  }


--- 1775,1782 ----
    mAgent=0;
    nsStr::Initialize(*this,mBuffer,sizeof(mBuffer)-1,0,eOneByte,PR_FALSE);
    AddNullTerminator(*this);
!   //Append(aString); -- oops, this'll construct an nsCString to coerce!
!   nsStr::Assign(*this,aString,0,aString.mLength,mAgent);
  }
Status: NEW → ASSIGNED
rickg: any progress on this? this is actually showing up in profiles that i've
been doing. would you like _me_ to check in the patch?
I've added nsCString::Append(nstr), and I'm testing it. Once I'm confident that
all is well I'll check it in. I haven't seen anything odd yet, so if you want to
add it to your build (temporarily) until I land my change, it *should* work fine
for you.
Status: ASSIGNED → RESOLVED
Closed: 25 years ago
Resolution: --- → FIXED
Fixed by latest update to nsCString. Added nsStr constructor. r=kmcclusk.
Component: XP Utilities → String
Keywords: perf, verifyme
QA Contact: rickg → scc
Summary: [perf] unexpected heap alloc in nsCAutoString::nsCAutoString(const nsStr&) → unexpected heap alloc in nsCAutoString::nsCAutoString(const nsStr&)
mass remove verifyme requests greater than 4 months old
Keywords: verifyme
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.