Closed Bug 212475 Opened 22 years ago Closed 22 years ago

Lazily get mEncoder in nsSegmentEncoder

Categories

(Core :: Networking, defect)

defect
Not set
normal

Tracking

()

VERIFIED FIXED

People

(Reporter: bzbarsky, Assigned: bzbarsky)

Details

Attachments

(2 files)

This goes sort of hand-in-hand with bug 212223. Even in my build that has some optimizations for GetCharsetAlias (eg caching the service) I see a decent speedup of nsStandardURL::SetSpec from the patch coming up...
Attached patch Proposed patchSplinter Review
I put the IsAscii in the same file at jag's suggestion; I don't really see that many other people using it.....
Attachment #127590 - Flags: superreview?(dbaron)
Attachment #127590 - Flags: review?(darin)
Comment on attachment 127590 [details] [diff] [review] Proposed patch >Index: netwerk/base/src/nsStandardURL.h >+ const char* mCharset; // Caller should keep this alive for nit: |const char *mCharset;| >Index: netwerk/base/src/nsStandardURL.cpp >+inline PRBool >+IsAscii(const char* str, PRUnichar len) >+{ >+ // Here "str" is a pointer to a UTF-8 buffer and we must have len >+ // be smaller than the length to the null terminator >+ const char* end = str + len; >+ while (str < end) { >+ NS_ASSERTION(*str, "Null byte before end of data!"); >+ if (0x80 & *str) >+ return PR_FALSE; >+ ++str; > } >+ return PR_TRUE; > } not too many compilers will inline a function containing a loop. also, i think this should be in nsCRT. if not, then when someone down the road needs this maybe they will not realize that it already exists. plus, this kind of function deserves to be in a more generic place. at the very least, move it into nsURLHelper.h (net_IsAscii).
Attachment #127590 - Flags: review?(darin) → review-
Attachment #127590 - Attachment is obsolete: true
Attachment #127590 - Attachment is obsolete: false
Attachment #127590 - Flags: superreview?(dbaron)
Attachment #127608 - Flags: review?(darin)
You could also use IsAscii(Substring(foo, foo+n)) if you don't want to add a new function for it.
er, IsASCII (in nsReadableUtils).
Yeah, we were semi-trying to avoid the cost of that; would that be faster than the "scan the whole string" thing we do right now for typical URI strings?
Comment on attachment 127608 [details] [diff] [review] The jag spell has worn off.... r=darin i think there is good use for this nsCRT function elsewhere in the codebase.
Attachment #127608 - Flags: review?(darin) → review+
Comment on attachment 127608 [details] [diff] [review] The jag spell has worn off.... David, what do you think? Would you rather I went the Substring() route?
Attachment #127608 - Flags: superreview?(dbaron)
bz: have you compared the amount of code generated by IsAscii(Substring(foo, foo+n)) and nsCRT::IsAscii(foo, n) not to mention the overhead of GetReadableFragment, etc. why should we be creating string objects when we don't need to? ...especially given that this code is executed A LOT.
Yes, I know. That's why I wrote it the way I did....
Attachment #127608 - Flags: superreview?(dbaron) → superreview+
Checked in. This improved Tp by 1-2%, looks like.....
Status: NEW → RESOLVED
Closed: 22 years ago
Resolution: --- → FIXED
Comment on attachment 127608 [details] [diff] [review] The jag spell has worn off.... + static PRBool IsAscii(const char* aString, PRUnichar aLength); |PRUnichar aLength|???
Aieee.. Total thinko. Fixed: -PRBool nsCRT::IsAscii(const char* aString, PRUnichar aLength) +PRBool nsCRT::IsAscii(const char* aString, PRUint32 aLength) and similar in the header. Thanks for catching that, jag.
Is there a whitebox/API test that can verify this change?
benc: no, not really.
V per Darin and bz' perf comments.
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: