WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
NEW
137374
Support insert iterators for Vectors. [Part 1]
https://bugs.webkit.org/show_bug.cgi?id=137374
Summary
Support insert iterators for Vectors. [Part 1]
Jer Noble
Reported
2014-10-02 18:08:19 PDT
Support insert iterators for Vectors.
Attachments
Patch
(9.44 KB, patch)
2014-10-02 21:20 PDT
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Patch
(11.38 KB, patch)
2014-10-03 10:51 PDT
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Patch
(10.51 KB, patch)
2014-10-03 10:59 PDT
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Patch
(12.45 KB, patch)
2014-10-03 11:01 PDT
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Patch
(44.92 KB, patch)
2014-10-03 22:54 PDT
,
Jer Noble
no flags
Details
Formatted Diff
Diff
Show Obsolete
(4)
View All
Add attachment
proposed patch, testcase, etc.
Jer Noble
Comment 1
2014-10-02 21:20:39 PDT
Created
attachment 239176
[details]
Patch
WebKit Commit Bot
Comment 2
2014-10-02 21:22:40 PDT
Attachment 239176
[details]
did not pass style-queue: ERROR: Source/WTF/wtf/VectorIterators.h:40: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:43: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:74: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:77: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] Total errors found: 4 in 3 files If any of these errors are false positives, please file a bug against check-webkit-style.
Daniel Bates
Comment 3
2014-10-03 10:46:20 PDT
Comment on
attachment 239176
[details]
Patch We should add unit tests for this functionality. You can see examples of unit tests in Tools/TestWebKitAPI/Tests. In particular, we have WTF-specific unit tests in Tools/TestWebKitAPI/Tests/WTF.
Jer Noble
Comment 4
2014-10-03 10:51:35 PDT
Created
attachment 239213
[details]
Patch
Jer Noble
Comment 5
2014-10-03 10:52:07 PDT
(In reply to
comment #3
)
> (From update of
attachment 239176
[details]
) > We should add unit tests for this functionality. You can see examples of unit tests in Tools/TestWebKitAPI/Tests. In particular, we have WTF-specific unit tests in Tools/TestWebKitAPI/Tests/WTF.
Oh I wrote them; but somehow managed to upload a patch without them. :-/
Daniel Bates
Comment 6
2014-10-03 10:52:28 PDT
We need to add file VectorIterators.h to the Windows and CMake build systems.
WebKit Commit Bot
Comment 7
2014-10-03 10:52:42 PDT
Attachment 239213
[details]
did not pass style-queue: ERROR: Source/WTF/wtf/VectorIterators.h:40: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:43: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:74: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:77: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] Total errors found: 4 in 5 files If any of these errors are false positives, please file a bug against check-webkit-style.
Jer Noble
Comment 8
2014-10-03 10:59:02 PDT
Created
attachment 239214
[details]
Patch
Anders Carlsson
Comment 9
2014-10-03 10:59:48 PDT
Why can't we use std::back_insert_iterator?
http://en.cppreference.com/w/cpp/iterator/back_insert_iterator
WebKit Commit Bot
Comment 10
2014-10-03 11:01:31 PDT
Attachment 239214
[details]
did not pass style-queue: ERROR: Source/WTF/wtf/VectorIterators.h:40: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:43: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:74: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:77: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] Total errors found: 4 in 5 files If any of these errors are false positives, please file a bug against check-webkit-style.
Jer Noble
Comment 11
2014-10-03 11:01:52 PDT
Created
attachment 239215
[details]
Patch
WebKit Commit Bot
Comment 12
2014-10-03 11:04:23 PDT
Attachment 239215
[details]
did not pass style-queue: ERROR: Source/WTF/wtf/VectorIterators.h:40: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:43: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:74: difference_type is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] ERROR: Source/WTF/wtf/VectorIterators.h:77: iterator_category is incorrectly named. Don't use underscores in your identifier names. [readability/naming/underscores] [4] Total errors found: 4 in 7 files If any of these errors are false positives, please file a bug against check-webkit-style.
Jer Noble
Comment 13
2014-10-03 11:04:57 PDT
(In reply to
comment #9
)
> Why can't we use std::back_insert_iterator? > >
http://en.cppreference.com/w/cpp/iterator/back_insert_iterator
Because Vector doesn't have a push_back(). Its iterator types also don't have the std standard typedefs, like value_type, etc.
Anders Carlsson
Comment 14
2014-10-03 11:35:52 PDT
(In reply to
comment #13
)
> (In reply to
comment #9
) > > Why can't we use std::back_insert_iterator? > > > >
http://en.cppreference.com/w/cpp/iterator/back_insert_iterator
> > Because Vector doesn't have a push_back(). Its iterator types also don't have the std standard typedefs, like value_type, etc.
I think it's much better to make our containers play well with the STL than it is to replicate STL functionality. (Our transition from OwnPtr to std::unique_ptr is an example of this).
Darin Adler
Comment 15
2014-10-03 12:41:09 PDT
(In reply to
comment #14
)
> (In reply to
comment #13
) > > (In reply to
comment #9
) > > > Why can't we use std::back_insert_iterator? > > > > > >
http://en.cppreference.com/w/cpp/iterator/back_insert_iterator
> > > > Because Vector doesn't have a push_back(). Its iterator types also don't have the std standard typedefs, like value_type, etc. > > I think it's much better to make our containers play well with the STL than it is to replicate STL functionality. (Our transition from OwnPtr to std::unique_ptr is an example of this).
I’m with Anders on this. Seems like a natural refinement to improve the Vector iterators, add push_back, and then use back_insert_iterator.
Jer Noble
Comment 16
2014-10-03 12:56:27 PDT
(In reply to
comment #15
)
> (In reply to
comment #14
) > > (In reply to
comment #13
) > > > (In reply to
comment #9
) > > > > Why can't we use std::back_insert_iterator? > > > > > > > >
http://en.cppreference.com/w/cpp/iterator/back_insert_iterator
> > > > > > Because Vector doesn't have a push_back(). Its iterator types also don't have the std standard typedefs, like value_type, etc. > > > > I think it's much better to make our containers play well with the STL than it is to replicate STL functionality. (Our transition from OwnPtr to std::unique_ptr is an example of this). > > I’m with Anders on this. Seems like a natural refinement to improve the Vector iterators, add push_back, and then use back_insert_iterator.
Okay, that's fine. And back_insert_iterator was actually my primary use-case anyway. But for insert_iterator, the default STL implementation won't work, as Vector invalidates all outstanding iterators when it does a re-alloc. The version I posted here works around this by resetting the internal iterator in that scenario, so it may still be useful as a template specification version of std::insert_Iterator.
Darin Adler
Comment 17
2014-10-03 21:38:59 PDT
(In reply to
comment #16
)
> But for insert_iterator, the default STL implementation won't work, as Vector invalidates all outstanding iterators when it does a re-alloc.
How does insert_iterator work with std::vector? If the answer is that it doesn’t then we should consider whether we have a good reason that we want WTF::Vector to work with it.
Jer Noble
Comment 18
2014-10-03 21:59:57 PDT
(In reply to
comment #17
)
> (In reply to
comment #16
) > > But for insert_iterator, the default STL implementation won't work, as Vector invalidates all outstanding iterators when it does a re-alloc. > > How does insert_iterator work with std::vector? If the answer is that it doesn’t then we should consider whether we have a good reason that we want WTF::Vector to work with it.
std::vector has the same problem, in that all iterators are invalidated in the event of a re-alloc. The way you'd make a insert_iterator work with std::vector is the same as with WTF::Vector: by increasing the container's capacity with reserve()/reserveCapacity() before the insert operations.
Jer Noble
Comment 19
2014-10-03 22:54:37 PDT
Created
attachment 239267
[details]
Patch Trying the alternative approach of making Vector compatible with back_insert_iterator and insert_iterator. This requires Vector to have an insert(iterator, value) method, which causes compile-time errors due to an ambiguity between insert(iterator, value) and insert(size_t, value) when passing in a literal (e.g., 0). So Part 1 is to rename insert(size_t, value) to insertAt(size_t, value), and Part 2 will be adding a new insert(iterator, value) method.
Brent Fulgham
Comment 20
2016-08-22 11:23:56 PDT
Was this abandoned? Should we be getting it up-to-date and landed?
Michael Catanzaro
Comment 21
2016-09-17 07:05:35 PDT
Comment on
attachment 239267
[details]
Patch Hi, Apologies that your patch was not reviewed in a timely manner. Since it's now quite old, I am removing it from the review request queue. Please consider rebasing it on trunk and resubmitting. To increase the chances of getting a review, consider using 'Tools/Scripts/webkit-patch upload --suggest-reviewers' to CC reviewers who might be interested in this bug.
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