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

RESOLVED FIXED

Status

()

defect
P3
major
RESOLVED FIXED
20 years ago
5 years ago

People

(Reporter: waterson, Assigned: rickg)

Tracking

({perf})

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

20 years ago
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);
  }
(Assignee)

Updated

20 years ago
Status: NEW → ASSIGNED
(Reporter)

Comment 1

20 years ago
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?
(Assignee)

Comment 2

20 years ago
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.
(Assignee)

Updated

20 years ago
Status: ASSIGNED → RESOLVED
Last Resolved: 20 years ago
Resolution: --- → FIXED
(Assignee)

Comment 3

20 years ago
Fixed by latest update to nsCString. Added nsStr constructor. r=kmcclusk.

Updated

18 years ago
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
You need to log in before you can comment on or make changes to this bug.