Closed Bug 499027 Opened 15 years ago Closed 15 years ago

Copying an empty string to a new string causes it to allocate a buffer

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
status1.9.2 --- beta1-fixed

People

(Reporter: neil, Assigned: neil)

Details

(Keywords: perf)

Attachments

(1 file, 2 obsolete files)

Steps to reproduce problem:
1. nsCString a, b;
2. a = b;
Expected result: nothing happens

Actual results: a now has a sharable buffer
Attached patch Possible patch (obsolete) — Splinter Review
As well as failing, if you compile with string stats you would notice that the new test consumes an extra string buffer without the empty copy optimisation.

I'm not sure that the test correctly tests for a new string buffer creation.

I also fixed an inconsistent memory allocation since I build with them fatal.
Assignee: nobody → neil
Status: NEW → ASSIGNED
Attachment #383805 - Flags: superreview?(dbaron)
Attachment #383805 - Flags: review?(dbaron)
Attached patch Correct patch (obsolete) — Splinter Review
Sorry, I forgot to check what I was diffing...
Attachment #383805 - Attachment is obsolete: true
Attachment #384139 - Flags: superreview?(dbaron)
Attachment #384139 - Flags: review?(dbaron)
Attachment #383805 - Flags: superreview?(dbaron)
Attachment #383805 - Flags: review?(dbaron)
Comment on attachment 384139 [details] [diff] [review]
Correct patch

I hate the way we implement VOIDED.  (I wish it were orthogonal to what was in the buffer.)  But anyway...

>+    if (str.mFlags & F_VOIDED)
>+      {
>+        // inherit the F_VOIDED attribute
>+        SetIsVoid(PR_TRUE);
>+      }
>+    else if (!str.mLength)
>+      {
>+        Truncate();
>+      }

Isn't it true that F_VOIDED should only be set when mLength is zero?  Can't we assert that and then combine these two clauses:

if (!str.mLength)
  {
    if (str.mFlags & F_VOIDED)
      SetIsVoid(PR_TRUE);
    else
      Truncate();
  }

or perhaps even:

if (!str.mLength)
  {
    Truncate();
    mFlags |= (str.mFlags & F_VOIDED);
  }



r=dbaron, but I'd like jst to sr to make sure that my assumption that it's expected for F_VOIDED to be propagated on assignment is correct (since I suppose right now that only happens some of the time).
Attachment #384139 - Flags: superreview?(jst)
Attachment #384139 - Flags: superreview?(dbaron)
Attachment #384139 - Flags: review?(dbaron)
Attachment #384139 - Flags: review+
Comment on attachment 384139 [details] [diff] [review]
Correct patch

sr=jst. I do think we should propagate the voided flag on assignment consistently.
Attachment #384139 - Flags: superreview?(jst) → superreview+
We already do, since we never set both F_SHARED and F_VOIDED simultaneously.
Attachment #384139 - Attachment is obsolete: true
Attachment #390535 - Flags: superreview?(jst)
Attachment #390535 - Flags: superreview?(jst) → superreview+
Pushed changeset f319ed9df9d4 to mozilla-central.
Status: ASSIGNED → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Very good Tp and sspider improvements here :)
Keywords: perf
Flags: blocking1.9.2?
Can we get a mozilla-1.9.2 patch nominated for approval, please?
Flags: wanted1.9.2+
Flags: blocking1.9.2?
Flags: blocking1.9.2-
Attachment #390535 - Flags: approval1.9.2+
Pushed changeset dcc67c2cb0f1 to releases/mozilla-1.9.2
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: