Closed
Bug 272277
Opened 20 years ago
Closed 20 years ago
Change to Append/Assign/Equals-Literal in networking
Categories
(Core :: Networking, defect)
Core
Networking
Tracking
()
RESOLVED
FIXED
People
(Reporter: mikael, Assigned: mikael)
Details
Attachments
(1 file, 3 obsolete files)
|
88.21 KB,
patch
|
Details | Diff | Splinter Review |
Change to Append/Assign/Equals-Literal in networking
| Assignee | ||
Comment 1•20 years ago
|
||
| Assignee | ||
Updated•20 years ago
|
Status: NEW → ASSIGNED
| Assignee | ||
Updated•20 years ago
|
Attachment #167359 -
Flags: superreview?(bzbarsky)
Attachment #167359 -
Flags: review?(cbiesinger)
Comment 2•20 years ago
|
||
replacing code like this:
foo = NS_LITERAL_CSTRING("xyz") + str;
with
foo.AssignLiteral("xyz");
foo.Append(str);
is probably not worth it. the advantage of using operator+ is that it causes
one assignment to be done. the string buffer will be allocated to exactly the
right size the first time, and the null terminator will be written once. the
operator+ code is pretty efficient, so i think unless you can provide a good
reason for this kind of change, i'd object to the change.
Comment 3•20 years ago
|
||
I'm not going to be able to get to this review in the near future (at least one week, possibly as long as five weeks).
| Assignee | ||
Comment 4•20 years ago
|
||
(In reply to comment #2) '> is probably not worth it. the advantage of using operator+ is that it causes > one assignment to be done. the string buffer will be allocated to exactly the > right size the first time, and the null terminator will be written once. the > operator+ code is pretty efficient, so i think unless you can provide a good > reason for this kind of change, i'd object to the change. The main reason is remove bloat. This generates quite a lot of big code. Most (but noll all) of the cases in the patch use a ns[C]AutoString and the resulting strings will fit into the 64-sized buffer
Comment 5•20 years ago
|
||
Comment on attachment 167359 [details] [diff] [review] proposed changes >Index: netwerk/protocol/http/src/nsHttpHandler.cpp >+ mOscpu.AssignLiteral("2.11"); Another option for this might be to make mOscpu be a nsDependentCString. Then you can call the "Rebind" method here to avoid a heap allocation and memcpy :) Same applies to some of the other strings that are apparently assigned only literal values. >Index: netwerk/protocol/http/src/nsHttpAuthCache.cpp > GetAuthKey(const char *scheme, const char *host, PRInt32 port, nsCString &key) > { >- key.Assign(nsDependentCString(scheme) + >- NS_LITERAL_CSTRING("://") + >- nsDependentCString(host) + >- NS_LITERAL_CSTRING(":")); >+ key.Assign(scheme); >+ key.AppendLiteral("://"); >+ key.Append(host); >+ key.Append(':'); > key.AppendInt(port); OK, good point about codesize. I agree. >Index: netwerk/protocol/http/src/nsHttpConnectionInfo.cpp >+ mHashKey.Append(nsPrintfCString(":%d", keyPort)); maybe change this to: .Append(':'); .AppendInt(keyPort); ?? >Index: netwerk/protocol/about/src/nsAboutCache.cpp >+ mBuffer.Truncate(); > if (!mDeviceID.IsEmpty()) { >+ mBuffer.AssignLiteral("</pre>\n"); > } perhaps moving the Truncate() call into an |else| clause would make more sense? sr=darin (with these nits fixed)
Attachment #167359 -
Flags: superreview?(bzbarsky) → superreview+
Comment 6•20 years ago
|
||
can you use the opportunity here and fix bug 134165?
| Assignee | ||
Comment 7•20 years ago
|
||
only mPlatform was made into an nsDependentCString I also changed a local var into nsCAutoString (from nsCString) as for bug 134165 - I'll attach a patch to that bug
Attachment #167359 -
Attachment is obsolete: true
| Assignee | ||
Comment 8•20 years ago
|
||
Comment on attachment 167575 [details] [diff] [review] updated with darin's comments I caught a problem with this patch
Attachment #167575 -
Attachment is obsolete: true
| Assignee | ||
Updated•20 years ago
|
Attachment #167359 -
Flags: review?(cbiesinger)
| Assignee | ||
Comment 9•20 years ago
|
||
in the last patch I used an AssignLiteral instead of an AppendLiteral, oops
| Assignee | ||
Updated•20 years ago
|
Attachment #167769 -
Flags: review?(cbiesinger)
Comment 10•20 years ago
|
||
Comment on attachment 167769 [details] [diff] [review] new patch netwerk/protocol/http/src/nsHttpHandler.cpp buf = (char*)name.sysname; hmm, wonder why that cast is needed... anyway, not your code netwerk/protocol/http/src/nsHttpDigestAuth.cpp + authString.AppendLiteral("auth"); if (qop & QOP_AUTH_INT) - authString += "auth-int"; - else - authString += "auth"; + authString.AppendLiteral("-int"); hm... why this? seems like this code will be slightly less efficient in the case where the if is hit... is there a gain? netwerk/protocol/http/src/nsHttpConnectionInfo.cpp - mHashKey.Assign(NS_LITERAL_CSTRING("..") + - nsDependentCString(keyHost) + - nsPrintfCString(":%d", keyPort)); + mHashKey.AssignLiteral(".."); + mHashKey.Append(keyHost); + mHashKey.AppendInt(keyPort); it seems like you lost a colon somewhere? netwerk/base/src/nsURLHelper.cpp + else if (name.EqualsLiteral(".") || name.IsEmpty()) { hmm, might be better to test IsEmpty() first, since that check should be cheaper...
Attachment #167769 -
Flags: review?(cbiesinger) → review+
Comment 11•20 years ago
|
||
Thanks for catching those errors biesi!
| Assignee | ||
Comment 12•20 years ago
|
||
Biesi, thanks for the Append(':') :-{
Attachment #167769 -
Attachment is obsolete: true
| Assignee | ||
Comment 13•20 years ago
|
||
Checked in 2004-12-04
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Comment 14•20 years ago
|
||
+ mHashKey.Append(';');
not ':'?| Assignee | ||
Comment 15•20 years ago
|
||
Thank you for finding that. Fixed Next time i will read one extra time :-(
You need to log in
before you can comment on or make changes to this bug.
Description
•