Closed
Bug 1305422
Opened 3 years ago
Closed 3 years ago
remove size_{forward,backward} and other similarly useless things from ns{Reading,Writing}Iterator
Categories
(Core :: XPCOM, defect, P3)
Core
XPCOM
P3
Tracking
()
RESOLVED
FIXED
mozilla52
Tracking | Status | |
---|---|---|
firefox52 | --- | fixed |
People
(Reporter: froydnj, Assigned: froydnj)
Details
Attachments
(20 files, 2 obsolete files)
ns{Reading,Writing}Iterator are strange beasts insofar as they know how much farther iteration can proceed before there is no more string to iterate over. This behavior is very unusual, and there are even comments that this behavior stems from when we had fragmented strings and iterators to match. ns{Reading,Writing}Iterator are also less powerful versions of mozilla::RangedPtr, so we should try to move them over to the more modern alternative. Getting rid of size_{forward,backward} is a good step in that direction.
![]() |
Assignee | |
Comment 2•3 years ago
|
||
We have better ways of checking for SetLength failure nowadays, and even if these SetLength calls did fail, the program would crash anyway.
Attachment #8794831 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 3•3 years ago
|
||
Asking for size_forward on an iterator that you haven't started reading from is just asking for the length of the original string, so use that instead.
Attachment #8794832 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 4•3 years ago
|
||
We don't need to bother with iterators here at all; we can just ask the string for its data and length directly.
Attachment #8794833 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 5•3 years ago
|
||
The implementation of Is8bit, with its multiply-nested loops, dates from the time when string iterators could be fragmented into multiple pieces. We no longer have such iterators, so we can write Is8bit much more straightforwardly, with the single loop you would expect.
Attachment #8794834 -
Flags: review?(amarchesini)
![]() |
Assignee | |
Comment 6•3 years ago
|
||
This change is necessary so we can start using a pair of iterators (current, end) and subtract them to figure out how far we have left to go. The current code just uses size_forward and size_backward for this purpose, and it's quite an unusual iterator that knows how far it can go until it's done.
Attachment #8794835 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 7•3 years ago
|
||
This change avoids calling size_forward on the iterator, which we are trying to eliminate.
Attachment #8794836 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 8•3 years ago
|
||
The implementation of SerializeAttr, with its multiply-nested loops, dates from the time when string iterators could be fragmented into multiple pieces. We no longer have such iterators, so we can write SerializeAttr much more straightforwardly.
Attachment #8794837 -
Flags: review?(bugs)
![]() |
Assignee | |
Comment 9•3 years ago
|
||
The surrounding code in this file and elsewhere uses pairs of RangedPtrs for iterators. While we're trying to modify nsString's iterators so they're more like RangedPtr, it seems reasonable to go ahead and modify this instance of nsString iterators to use RangedPtr directly for conformity with the surrounding code.
Attachment #8794838 -
Flags: review?(dholbert)
![]() |
Assignee | |
Comment 10•3 years ago
|
||
These methods are now unused thanks to previous patches.
Attachment #8794839 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 11•3 years ago
|
||
See comment 0 for the rationale on why we want to remove size_forward calls.
Attachment #8794840 -
Flags: review?(amarchesini)
![]() |
Assignee | |
Comment 12•3 years ago
|
||
See comment 0 for the rationale on why we want to remove size_forward calls.
Attachment #8794841 -
Flags: review?(erahm)
![]() |
Assignee | |
Comment 13•3 years ago
|
||
See comment 0 for the rationale on why we want to remove size_forward calls.
Attachment #8794842 -
Flags: review?(bkelly)
![]() |
Assignee | |
Comment 14•3 years ago
|
||
See comment 0 for the rationale on why we want to remove size_forward calls.
Attachment #8794843 -
Flags: review?(amarchesini)
![]() |
Assignee | |
Comment 15•3 years ago
|
||
See comment 0 for the rationale on why we want to remove size_forward calls.
Attachment #8794844 -
Flags: review?(bkelly)
![]() |
Assignee | |
Comment 16•3 years ago
|
||
nsCString::const_iterator and friends currently hold pointers to not only the current iterator position, but also the start and end of the string. This functionality enables them to compute their position from the start and the end of the string, respectively, but we have better ways of accomplishing the same thing (e.g. mozilla::RangedPtr), and it's a bit unusual for iterators to know their current position anyway. So let's make nsPKCS12Blob, when reading digests, hold pointers to both the current iterator position and the end iterator position, and calculate the remaining amount to read from those two pieces of information. I apologize in advance for modifying this grotty code. I think I could have written this patch more cleanly, but then it would have been mixed up between changes and cleanup, and I think it would have been harder to review.
Attachment #8794845 -
Flags: review?(dkeeler)
![]() |
Assignee | |
Comment 17•3 years ago
|
||
See comment 0 for the rationale on why we want to remove size_forward calls.
Attachment #8794846 -
Flags: review?(ted)
![]() |
Assignee | |
Comment 19•3 years ago
|
||
We don't support IBM VisualAge for OS/2 anymore, and we haven't needed this code in a long time regardless.
Attachment #8794848 -
Flags: review?(erahm)
Updated•3 years ago
|
Attachment #8794834 -
Flags: review?(amarchesini) → review+
Updated•3 years ago
|
Attachment #8794840 -
Flags: review?(amarchesini) → review+
Updated•3 years ago
|
Attachment #8794843 -
Flags: review?(amarchesini) → review+
Updated•3 years ago
|
Assignee: nobody → nfroyd
Status: NEW → ASSIGNED
Updated•3 years ago
|
Attachment #8794838 -
Flags: review?(dholbert) → review+
Updated•3 years ago
|
Attachment #8794830 -
Flags: review?(erahm) → review+
Updated•3 years ago
|
Attachment #8794831 -
Flags: review?(erahm) → review+
Updated•3 years ago
|
Attachment #8794832 -
Flags: review?(erahm) → review+
Comment on attachment 8794845 [details] [diff] [review] part 15 - don't call size_forward in nsPKCS12Blob Review of attachment 8794845 [details] [diff] [review]: ----------------------------------------------------------------- I would actually prefer to remove the code that calls this entirely since it's completely unnecessary (NSS has this functionality built-in). I wanted to prove to myself that this would work, so I wound up just writing the patch. I'll attach it shortly.
Attachment #8794845 -
Flags: review?(dkeeler)
Attachment #8794928 -
Flags: review?(nfroyd)
Attachment #8794928 -
Flags: review?(mgoodwin)
Updated•3 years ago
|
Attachment #8794833 -
Flags: review?(erahm) → review+
![]() |
Assignee | |
Comment 22•3 years ago
|
||
Comment on attachment 8794928 [details] [diff] [review] part 15 - don't call size_forward in nsPKCS12Blob (code removal version) Review of attachment 8794928 [details] [diff] [review]: ----------------------------------------------------------------- Fantastic, thank you!
Attachment #8794928 -
Flags: review?(nfroyd) → review+
Comment 23•3 years ago
|
||
Comment on attachment 8794835 [details] [diff] [review] part 6a - add operator- support for ns{Reading,Writing}Iterator Review of attachment 8794835 [details] [diff] [review]: ----------------------------------------------------------------- ::: xpcom/string/nsStringIterator.h @@ +131,5 @@ > } > + > + difference_type operator-(const self_type& aOther) > + { > + MOZ_ASSERT(mPosition >= aOther.mPosition); I'm not sure we should be asserting here. We return |difference_type| (aka ptrdiff_t) which is signed, so that implies we allow for negative distances. I *could* see an argument for asserting that the iterators are working on the same string, something like MOZ_ASSERT(mStart == aOther.mStart && mEnd == aOther.mEnd) but that seems a bit gratuitous and I'm guessing we want to get rid of mStart and mEnd anyhow. @@ +267,5 @@ > } > + > + difference_type operator-(const self_type& aOther) > + { > + MOZ_ASSERT(mPosition >= aOther.mPosition); ditto
Attachment #8794835 -
Flags: review?(erahm) → review-
Updated•3 years ago
|
Attachment #8794836 -
Flags: review?(erahm) → review+
Updated•3 years ago
|
Attachment #8794839 -
Flags: review?(erahm) → review+
Updated•3 years ago
|
Attachment #8794841 -
Flags: review?(erahm) → review+
Comment 24•3 years ago
|
||
Comment on attachment 8794847 [details] [diff] [review] part 17 - remove size_{forward,backward} from ns{Reading,Writing}Iterator Review of attachment 8794847 [details] [diff] [review]: ----------------------------------------------------------------- \o/
Attachment #8794847 -
Flags: review?(erahm) → review+
Updated•3 years ago
|
Attachment #8794848 -
Flags: review?(erahm) → review+
![]() |
Assignee | |
Comment 25•3 years ago
|
||
Didn't code this up right the first time, let's try again.
Attachment #8794996 -
Flags: review?(ted)
![]() |
Assignee | |
Updated•3 years ago
|
Attachment #8794846 -
Attachment is obsolete: true
Attachment #8794846 -
Flags: review?(ted)
Updated•3 years ago
|
Attachment #8794837 -
Flags: review?(bugs) → review+
![]() |
Assignee | |
Comment 26•3 years ago
|
||
Version 2 of this patch adds some rationale for why we do what we do and changes the result type of operator-.
Attachment #8795018 -
Flags: review?(erahm)
![]() |
Assignee | |
Updated•3 years ago
|
Attachment #8794835 -
Attachment is obsolete: true
Comment 27•3 years ago
|
||
Comment on attachment 8795018 [details] [diff] [review] part 6a - add operator- support for ns{Reading,Writing}Iterator Review of attachment 8795018 [details] [diff] [review]: ----------------------------------------------------------------- Looks good, you can also get rid of the uint32_t casts in part 6 now I think.
Attachment #8795018 -
Flags: review?(erahm) → review+
Updated•3 years ago
|
Attachment #8794928 -
Flags: review?(mgoodwin) → review+
Comment 28•3 years ago
|
||
Comment on attachment 8794996 [details] [diff] [review] part 16 - don't call size_backward in nsExceptionHandler.cpp Review of attachment 8794996 [details] [diff] [review]: ----------------------------------------------------------------- I don't think we actually have a test for this, that might be useful. You could shoehorn it in here: https://dxr.mozilla.org/mozilla-central/rev/c55bcb7c777ea09431b4d16903ed079ae5632648/toolkit/crashreporter/test/unit/test_crashreporter_crash.js#34 We have tests for bad chars in keys, but not for the escaping we do for values: https://dxr.mozilla.org/mozilla-central/rev/c55bcb7c777ea09431b4d16903ed079ae5632648/toolkit/crashreporter/test/unit/test_crashreporter.js#47 Unrelated, but I wish I had just made the .extra file JSON when I originally wrote this code.
Attachment #8794996 -
Flags: review?(ted) → review+
Updated•3 years ago
|
Attachment #8794842 -
Flags: review?(bkelly) → review+
Updated•3 years ago
|
Attachment #8794844 -
Flags: review?(bkelly) → review+
Comment 29•3 years ago
|
||
Pushed by nfroyd@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/77a8d7d6a0fb part 1 - remove normalize* methods from ns{Reading,Writing}Iterator; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/8313868b4334 part 2 - don't call size_forward on ns*String::iterators to check for SetLength failure; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/e208dfe24c94 part 3 - don't call size_forward in nsTStringComparator.cpp; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/a5b04e48b3e8 part 4 - don't call size_forward in nsIDNService.cpp; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/1c06cb170aa8 part 5 - simplify Is8bit; r=baku https://hg.mozilla.org/integration/mozilla-inbound/rev/9b814ee26cd7 part 6a - add operator- support for ns{Reading,Writing}Iterator; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/9dc21248ab12 part 6 - pass explicit end iterators for CopyTo{Upper,Lower}Case; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/caad2bb558f6 part 7 - simplify nsXMLContentSerializer::SerializeAttr; r=smaug https://hg.mozilla.org/integration/mozilla-inbound/rev/8c6e2e1c4f2a part 8 - make nsSMILParserUtils::CheckForNegativeNumber more idiomatic; r=dholbert https://hg.mozilla.org/integration/mozilla-inbound/rev/55be43ac96c9 part 9 - remove {start,end} from ns{Reading,Writing}Iterator; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/32b8ba9f7a51 part 10 - don't call size_forward in nsHTMLContentSerializer.cpp; r=baku https://hg.mozilla.org/integration/mozilla-inbound/rev/088bfcd8f3cb part 11 - don't call size_forward in nsXPCOMStrings.cpp; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/17a8607397e5 part 12 - don't call size_forward in {Body,Fetch}Util.cpp; r=bkelly https://hg.mozilla.org/integration/mozilla-inbound/rev/b26623101a0d part 13 - don't call size_forward in nsXMLContentSerializer.cpp; r=baku https://hg.mozilla.org/integration/mozilla-inbound/rev/e8f15fc02cfc part 14 - don't call size_forward in nsDefaultURIFixup.cpp; r=bkelly https://hg.mozilla.org/integration/mozilla-inbound/rev/daf738c4a411 part 15 - don't call size_forward in nsPKCS12Blob; r=mgoodwin,nfroyd https://hg.mozilla.org/integration/mozilla-inbound/rev/8ad96d4c9d42 part 16 - don't call size_backward in nsExceptionHandler.cpp; r=ted.mielczarek https://hg.mozilla.org/integration/mozilla-inbound/rev/f933f6215b9d part 17 - remove size_{forward,backward} from ns{Reading,Writing}Iterator; r=erahm https://hg.mozilla.org/integration/mozilla-inbound/rev/c8c685a95ab0 part 18 - remove #if 0'd-out code from nsStringIterator.h; r=erahm
Comment 30•3 years ago
|
||
Pushed by nfroyd@mozilla.com: https://hg.mozilla.org/integration/mozilla-inbound/rev/3caff20982f8 followup - use correct check for memory allocation failure in nsWindowsRegKey.cpp; r=bustage
Comment 31•3 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/77a8d7d6a0fb https://hg.mozilla.org/mozilla-central/rev/8313868b4334 https://hg.mozilla.org/mozilla-central/rev/e208dfe24c94 https://hg.mozilla.org/mozilla-central/rev/a5b04e48b3e8 https://hg.mozilla.org/mozilla-central/rev/1c06cb170aa8 https://hg.mozilla.org/mozilla-central/rev/9b814ee26cd7 https://hg.mozilla.org/mozilla-central/rev/9dc21248ab12 https://hg.mozilla.org/mozilla-central/rev/caad2bb558f6 https://hg.mozilla.org/mozilla-central/rev/8c6e2e1c4f2a https://hg.mozilla.org/mozilla-central/rev/55be43ac96c9 https://hg.mozilla.org/mozilla-central/rev/32b8ba9f7a51 https://hg.mozilla.org/mozilla-central/rev/088bfcd8f3cb https://hg.mozilla.org/mozilla-central/rev/17a8607397e5 https://hg.mozilla.org/mozilla-central/rev/b26623101a0d https://hg.mozilla.org/mozilla-central/rev/e8f15fc02cfc https://hg.mozilla.org/mozilla-central/rev/daf738c4a411 https://hg.mozilla.org/mozilla-central/rev/8ad96d4c9d42 https://hg.mozilla.org/mozilla-central/rev/f933f6215b9d https://hg.mozilla.org/mozilla-central/rev/c8c685a95ab0 https://hg.mozilla.org/mozilla-central/rev/3caff20982f8
Status: ASSIGNED → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla52
You need to log in
before you can comment on or make changes to this bug.
Description
•