Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(500)

Issue 11931034: Add methods to Collection. (Closed)

Created:
7 years, 11 months ago by Lasse Reichstein Nielsen
Modified:
7 years, 11 months ago
Reviewers:
floitsch
CC:
reviews_dartlang.org
Visibility:
Public.

Description

Add methods to Collection. Methods are: - void add(E) - void addAll(Iterable<E>) - void remove(Object) - void removeAll(Iterable) - void retainAll(Iterable) - void removeMatching(bool test(E)) - void retainMatching(bool test(E)) They have been implemented for List and Set only. Default implementations of removeX methods in Collections assume an efficient remove method, which Lists won't have. Committed: https://code.google.com/p/dart/source/detail?r=17257

Patch Set 1 #

Patch Set 2 : Also on DoubleLinkedQueue. #

Total comments: 35

Patch Set 3 : Merged to head. #

Patch Set 4 : address comments. #

Patch Set 5 : Address comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+2438 lines, -262 lines) Patch
M editor/tools/plugins/com.google.dart.tools.debug.core/src/com/google/dart/tools/debug/core/logical/MapStructureType.java View 1 2 3 4 chunks +7 lines, -7 lines 0 comments Download
M editor/util/debuggertest/pets.dart View 1 2 3 3 chunks +8 lines, -8 lines 0 comments Download
M pkg/serialization/lib/src/serialization_rule.dart View 1 chunk +6 lines, -1 line 0 comments Download
M runtime/lib/array.dart View 1 2 2 chunks +50 lines, -0 lines 0 comments Download
M runtime/lib/byte_array.dart View 1 2 2 chunks +55 lines, -0 lines 0 comments Download
M runtime/lib/growable_array.dart View 1 2 1 chunk +15 lines, -0 lines 0 comments Download
M sdk/lib/_internal/compiler/implementation/lib/js_array.dart View 1 2 1 chunk +27 lines, -0 lines 0 comments Download
M sdk/lib/collection/collections.dart View 1 2 3 1 chunk +74 lines, -0 lines 0 comments Download
M sdk/lib/core/collection.dart View 1 2 3 1 chunk +75 lines, -3 lines 0 comments Download
M sdk/lib/core/list.dart View 1 2 3 3 chunks +23 lines, -3 lines 0 comments Download
M sdk/lib/core/queue.dart View 1 2 3 1 chunk +38 lines, -0 lines 0 comments Download
M sdk/lib/core/set.dart View 1 2 3 6 chunks +17 lines, -49 lines 0 comments Download
M sdk/lib/html/dart2js/html_dart2js.dart View 1 2 3 40 chunks +814 lines, -73 lines 0 comments Download
M sdk/lib/html/dartium/html_dartium.dart View 40 chunks +814 lines, -73 lines 0 comments Download
M sdk/lib/html/html_common/filtered_element_list.dart View 1 2 2 chunks +30 lines, -1 line 0 comments Download
M sdk/lib/svg/dart2js/svg_dart2js.dart View 1 2 3 11 chunks +137 lines, -17 lines 0 comments Download
M sdk/lib/svg/dartium/svg_dartium.dart View 1 2 3 11 chunks +137 lines, -17 lines 0 comments Download
M tools/dom/src/CssClassSet.dart View 3 chunks +16 lines, -3 lines 0 comments Download
M tools/dom/templates/html/impl/impl_Element.darttemplate View 1 2 3 chunks +49 lines, -4 lines 0 comments Download
M tools/dom/templates/html/impl/impl_Node.darttemplate View 1 2 3 1 chunk +23 lines, -0 lines 0 comments Download
M tools/dom/templates/immutable_list_mixin.darttemplate View 1 2 2 chunks +23 lines, -3 lines 0 comments Download

Messages

Total messages: 3 (0 generated)
Lasse Reichstein Nielsen
7 years, 11 months ago (2013-01-17 07:52:38 UTC) #1
floitsch
LGTM. https://codereview.chromium.org/11931034/diff/2001/sdk/lib/collection/collections.dart File sdk/lib/collection/collections.dart (right): https://codereview.chromium.org/11931034/diff/2001/sdk/lib/collection/collections.dart#newcode53 sdk/lib/collection/collections.dart:53: * is efficient, which it isn't for, e.g., ...
7 years, 11 months ago (2013-01-17 13:36:58 UTC) #2
Lasse Reichstein Nielsen
7 years, 11 months ago (2013-01-18 11:41:48 UTC) #3
Message was sent while issue was closed.
https://codereview.chromium.org/11931034/diff/2001/sdk/lib/collection/collect...
File sdk/lib/collection/collections.dart (right):

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/collection/collect...
sdk/lib/collection/collections.dart:53: * is efficient, which it isn't for,
e.g., [List]s.
On 2013/01/17 13:36:58, floitsch wrote:
> too much "." and "," and latin.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.dart
File sdk/lib/core/collection.dart (right):

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:28: int get length;
Reasonable. We can write on List and Set that they are efficient.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:33: * After this, the [contains] method should
return true for that
On 2013/01/17 13:36:58, floitsch wrote:
> I would remove this line. Seems obvious.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:44: void addAll(Iterable<E> elements);
On 2013/01/17 13:36:58, floitsch wrote:
> Provide default implementation.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:63: void removeAll(Iterable elements);
On 2013/01/17 13:36:58, floitsch wrote:
> Provide default implementation.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:69: * Afterwards this collection should contain
only elements that
On 2013/01/17 13:36:58, floitsch wrote:
> Seems obvious.
> 
> Maybe mention "intersection" ?

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:72: void retainAll(Iterable elements);
On 2013/01/17 13:36:58, floitsch wrote:
> Provide default implementation.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:79: void removeMatching(bool test(E element));
On 2013/01/17 13:36:58, floitsch wrote:
> Provide default implementation.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:84: * An elements [:e:] satisfies [test] if
[:test(e):] is true.
Double negative is not an improvement, and it says the same thing.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/collection.da...
sdk/lib/core/collection.dart:86: void retainMatching(bool test(E element));
On 2013/01/17 13:36:58, floitsch wrote:
> Provide default implementation.

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/list.dart
File sdk/lib/core/list.dart (right):

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/list.dart#new...
sdk/lib/core/list.dart:309: "Cannot remove in an unmodifiable list");
On 2013/01/17 13:36:58, floitsch wrote:
> remove from ...

Done.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/queue.dart
File sdk/lib/core/queue.dart (right):

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/queue.dart#ne...
sdk/lib/core/queue.dart:215: void removeAll(Iterable elements) {
This implementation is not the default implementation.
The default implementation of Collections.removeAll assumes efficient remove, so
successive calls to remove is efficient.
This implementation instead creates an efficient check for being in elements and
uses removeMatching.

I'll add this as Collections.removeAllList.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/queue.dart#ne...
sdk/lib/core/queue.dart:225: void retainAll(Iterable elements) {
This one is the same as the default, so it can be removed.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/set.dart
File sdk/lib/core/set.dart (right):

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/set.dart#newc...
sdk/lib/core/set.dart:35: bool remove(Object value);
Object is correct here. We only use ==, possibly hashCode.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/set.dart#newc...
sdk/lib/core/set.dart:77: class _HashSetImpl<E> extends Iterable<E> implements
HashSet<E> {
Must be Collection, HashSet doesn't have a generative constructor.

Pah, I'll just remove _HashSetImpl and make HashSet be it.

https://codereview.chromium.org/11931034/diff/2001/sdk/lib/core/set.dart#newc...
sdk/lib/core/set.dart:109: void removeAll(Iterable elements) {
On 2013/01/17 13:36:58, floitsch wrote:
> should not be necessary if Collection provides default implementations.
> Same below.

Done.

https://codereview.chromium.org/11931034/diff/2001/tools/dom/templates/html/i...
File tools/dom/templates/html/impl/impl_Node.darttemplate (right):

https://codereview.chromium.org/11931034/diff/2001/tools/dom/templates/html/i...
tools/dom/templates/html/impl/impl_Node.darttemplate:93: void remove(Object
object) {
Good question. I can't remember why I didn't add them here, or if there even was
a reason. I'll add them and see if anything breaks.

Powered by Google App Engine
This is Rietveld 408576698