WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
141321
Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda functions
https://bugs.webkit.org/show_bug.cgi?id=141321
Summary
Add Vector::removeFirstMatching() / removeAllMatching() methods taking lambda...
Chris Dumez
Reported
2015-02-05 20:23:21 PST
Add Vector::removeFirstIf() / removeAllIf() methods taking lambda functions to match the element(s) to remove.
Attachments
Patch
(24.38 KB, patch)
2015-02-05 22:10 PST
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(24.38 KB, patch)
2015-02-06 09:20 PST
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Patch
(24.47 KB, patch)
2015-02-07 16:02 PST
,
Chris Dumez
no flags
Details
Formatted Diff
Diff
Show Obsolete
(2)
View All
Add attachment
proposed patch, testcase, etc.
Chris Dumez
Comment 1
2015-02-05 22:10:56 PST
Created
attachment 246149
[details]
Patch
WebKit Commit Bot
Comment 2
2015-02-05 22:13:10 PST
Attachment 246149
[details]
did not pass style-queue: ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:470: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:471: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:472: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:476: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:478: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:480: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:483: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:486: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:495: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:496: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:497: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:501: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:503: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:505: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:510: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:513: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:516: More than one command on the same line [whitespace/newline] [4] Total errors found: 17 in 23 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 3
2015-02-06 09:20:43 PST
Created
attachment 246163
[details]
Patch
Anders Carlsson
Comment 4
2015-02-06 09:25:05 PST
Comment on
attachment 246163
[details]
Patch I don't like the name removeAllIf; it sounds like it'll clear the vector if the lambda returns true.
Chris Dumez
Comment 5
2015-02-06 09:26:52 PST
(In reply to
comment #4
)
> Comment on
attachment 246163
[details]
> Patch > > I don't like the name removeAllIf; it sounds like it'll clear the vector if > the lambda returns true.
No argument there. We need to find better names for removeFirst(value) / removeFirstIf(lambda), removeAll(value) / removeAllIf(lambda). Do you have any suggestion?
WebKit Commit Bot
Comment 6
2015-02-06 09:30:12 PST
Attachment 246163
[details]
did not pass style-queue: ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:470: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:471: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:472: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:476: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:478: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:480: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:483: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:486: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:495: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:496: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:497: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:501: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:503: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:505: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:510: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:513: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:516: More than one command on the same line [whitespace/newline] [4] Total errors found: 17 in 23 files If any of these errors are false positives, please file a bug against check-webkit-style.
Chris Dumez
Comment 7
2015-02-06 16:03:34 PST
I have the following naming proposal: - removeAt(index) - removeSingle(value) // first occurrence - removeSingleIf(lambda) // first match - remove(value) // every occurrence - removeIf(lamba) // every match Any thoughts?
Chris Dumez
Comment 8
2015-02-07 11:12:55 PST
(In reply to
comment #7
)
> I have the following naming proposal: > - removeAt(index) > - removeSingle(value) // first occurrence > - removeSingleIf(lambda) // first match > - remove(value) // every occurrence > - removeIf(lamba) // every match > > Any thoughts?
Darin, what do you think about this naming? Do you have a better proposal?
Darin Adler
Comment 9
2015-02-07 11:36:53 PST
I am trying to find some prior art. I think I prefer "First" to "Single" but there is something that rubs me the wrong way about using "if" to mean "based on a predicate", because "if" sounds like it’s the entire function that’s conditional, not just something the function does. I would never say “remove all if equal to 5”, I would say “remove all that are equal to 5” or “remove all if there was a problem”. I am trying to find some prior art on naming functions that take predicates. Even better if it was in a project that used a sort of “literate” naming style reminiscent to the one from Cocoa, which inspires a lot of our function naming in WebKit.
Darin Adler
Comment 10
2015-02-07 11:39:49 PST
Cocoa uses the words “using block” and “passing test” in their NSArray functions. Neither seems terse enough for our purposes.
Chris Dumez
Comment 11
2015-02-07 11:43:06 PST
(In reply to
comment #9
)
> I am trying to find some prior art. I think I prefer "First" to "Single" but > there is something that rubs me the wrong way about using "if" to mean > "based on a predicate", because "if" sounds like it’s the entire function > that’s conditional, not just something the function does. > > I would never say “remove all if equal to 5”, I would say “remove all that > are equal to 5” or “remove all if there was a problem”. > > I am trying to find some prior art on naming functions that take predicates. > Even better if it was in a project that used a sort of “literate” naming > style reminiscent to the one from Cocoa, which inspires a lot of our > function naming in WebKit.
Well, STL has remove_if:
http://en.cppreference.com/w/cpp/algorithm/remove
I agree that removeAllIf() is confusing, which is why my latest proposal is removeIf().
Chris Dumez
Comment 12
2015-02-07 15:52:52 PST
For the lambda function, we could also use a method name with "Matching" in the name, e.g.: removeFirstMatching(lambda) / removeAllMatching(lambda)
Chris Dumez
Comment 13
2015-02-07 16:02:56 PST
Created
attachment 246224
[details]
Patch
WebKit Commit Bot
Comment 14
2015-02-07 16:04:21 PST
Attachment 246224
[details]
did not pass style-queue: ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:470: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:471: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:472: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:476: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:478: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:480: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:483: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:486: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:495: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:496: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:497: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:501: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:503: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:505: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:510: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:513: More than one command on the same line [whitespace/newline] [4] ERROR: Tools/TestWebKitAPI/Tests/WTF/Vector.cpp:516: More than one command on the same line [whitespace/newline] [4] Total errors found: 17 in 23 files If any of these errors are false positives, please file a bug against check-webkit-style.
Darin Adler
Comment 15
2015-02-07 17:13:39 PST
Comment on
attachment 246224
[details]
Patch I like these “matching” names. And they are nice and long and easy to globally replace if we get another naming idea.
Anders Carlsson
Comment 16
2015-02-07 17:48:04 PST
(In reply to
comment #15
)
> Comment on
attachment 246224
[details]
> Patch > > I like these “matching” names. And they are nice and long and easy to > globally replace if we get another naming idea.
I agree.
Chris Dumez
Comment 17
2015-02-07 17:48:38 PST
(In reply to
comment #16
)
> (In reply to
comment #15
) > > Comment on
attachment 246224
[details]
> > Patch > > > > I like these “matching” names. And they are nice and long and easy to > > globally replace if we get another naming idea. > > I agree.
\o/
WebKit Commit Bot
Comment 18
2015-02-07 18:28:54 PST
Comment on
attachment 246224
[details]
Patch Clearing flags on attachment: 246224 Committed
r179791
: <
http://trac.webkit.org/changeset/179791
>
WebKit Commit Bot
Comment 19
2015-02-07 18:29:00 PST
All reviewed patches have been landed. Closing 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