WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
213588
Add a new templated string type to help write more idiomatic parsing code
https://bugs.webkit.org/show_bug.cgi?id=213588
Summary
Add a new templated string type to help write more idiomatic parsing code
Sam Weinig
Reported
2020-06-24 19:29:20 PDT
Add a new templated string type to help write more idiomatic parsing code
Attachments
Patch
(25.23 KB, patch)
2020-06-24 19:38 PDT
,
Sam Weinig
no flags
Details
Formatted Diff
Diff
Patch
(20.86 KB, patch)
2020-06-25 10:29 PDT
,
Sam Weinig
no flags
Details
Formatted Diff
Diff
Patch
(21.09 KB, patch)
2020-06-25 13:27 PDT
,
Sam Weinig
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Sam Weinig
Comment 1
2020-06-24 19:31:10 PDT
While working on
https://bugs.webkit.org/show_bug.cgi?id=213460
, it became clear having a typed string type that worked with our parsing idioms would be a nice code improvement. Breaking off that work into this bug.
Sam Weinig
Comment 2
2020-06-24 19:38:53 PDT
Comment hidden (obsolete)
Created
attachment 402709
[details]
Patch
Sam Weinig
Comment 3
2020-06-25 10:29:32 PDT
Created
attachment 402746
[details]
Patch
Darin Adler
Comment 4
2020-06-25 11:05:12 PDT
Comment on
attachment 402746
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=402746&action=review
I would prefer if there was at least one use going in with the class.
> Source/WTF/wtf/text/StringParsingBuffer.h:42 > + constexpr StringParsingBuffer() > + { > + }
Maybe = default for this one?
> Source/WTF/wtf/text/StringParsingBuffer.h:48 > + }
Maybe: ASSERT(characters || !length)
> Source/WTF/wtf/text/StringParsingBuffer.h:54 > + }
ASSERT(!characters == !end) so we don’t pass a null by accident.
> Source/WTF/wtf/text/StringParsingBuffer.h:57 > + constexpr const CharacterType* position() const { return m_position; } > + constexpr const CharacterType* end() const { return m_end; }
Can these use auto instead of const CharacterType*?
> Source/WTF/wtf/text/StringParsingBuffer.h:67 > + ASSERT(m_position + i < m_end);
Also ASSERT(m_position < m_end) to be overflow-proof?
> Source/WTF/wtf/text/StringParsingBuffer.h:73 > + return *m_position;
ASSERT(m_position < m_end);
> Source/WTF/wtf/text/StringParsingBuffer.h:78 > + ++m_position;
ASSERT(m_position < m_end);
> Source/WTF/wtf/text/StringParsingBuffer.h:83 > + m_position += places;
ASSERT(m_position <= m_end); ASSERT(m_position + places <= m_end);
> Source/WTF/wtf/text/StringParsingBuffer.h:95 > + ++(*this);
No need for the parentheses.
Sam Weinig
Comment 5
2020-06-25 13:27:30 PDT
Created
attachment 402803
[details]
Patch
Darin Adler
Comment 6
2020-06-25 13:41:03 PDT
Comment on
attachment 402803
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=402803&action=review
> Source/WTF/wtf/text/StringParsingBuffer.h:54 > + ASSERT(m_end >= m_position); > + ASSERT(!characters == !end);
Maybe also assert that the length fits in unsigned?
> Source/WTF/wtf/text/StringParsingBuffer.h:69 > + ASSERT(m_position + i < m_end);
On reflection, because of overflow I think should be written like this: ASSERT(i < lengthRemaining());
> Source/WTF/wtf/text/StringParsingBuffer.h:75 > + ASSERT(m_position < m_end);
New, better idea: ASSERT(hasCharactersRemaining());
> Source/WTF/wtf/text/StringParsingBuffer.h:81 > + ASSERT(m_position < m_end);
Ditto.
> Source/WTF/wtf/text/StringParsingBuffer.h:85 > + constexpr void advanceBy(unsigned places)
Wonder if this should be size_t instead of unsigned.
> Source/WTF/wtf/text/StringParsingBuffer.h:87 > + ASSERT(m_position <= m_end);
I guess it was silly that I suggested this one. Obviously, this is the class's invariant, so we could assert this anywhere.
> Source/WTF/wtf/text/StringParsingBuffer.h:88 > + ASSERT(m_position + places <= m_end);
On reflection, because of overflow I think should be written like this: ASSERT(places <= lengthRemaining());
EWS
Comment 7
2020-06-25 14:13:23 PDT
Committed
r263529
: <
https://trac.webkit.org/changeset/263529
> All reviewed patches have been landed. Closing bug and clearing flags on
attachment 402803
[details]
.
Darin Adler
Comment 8
2020-06-25 15:12:54 PDT
Hope you don’t mind my after-commit comments!
Radar WebKit Bug Importer
Comment 9
2020-06-25 17:18:26 PDT
<
rdar://problem/64781816
>
Sam Weinig
Comment 10
2020-06-25 17:22:13 PDT
(In reply to Darin Adler from
comment #8
)
> Hope you don’t mind my after-commit comments!
Not in the slightest.
Radar WebKit Bug Importer
Comment 11
2020-06-25 17:22:28 PDT
<
rdar://problem/64781954
>
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug