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

Unified Diff: sdk/lib/_internal/lib/collection_patch.dart

Issue 26280002: Set.add returns true if item has been added, otherwise false (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: again Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/core/set.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/lib/collection_patch.dart
diff --git a/sdk/lib/_internal/lib/collection_patch.dart b/sdk/lib/_internal/lib/collection_patch.dart
index 7c1bbf107decbe6eb856735a4dce92473df54fe7..e98bac663afff7b964e0016f3e9ff8b323ad2b58 100644
--- a/sdk/lib/_internal/lib/collection_patch.dart
+++ b/sdk/lib/_internal/lib/collection_patch.dart
@@ -1002,15 +1002,15 @@ class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> {
}
// Collection.
- void add(E element) {
+ bool add(E element) {
if (_isStringElement(element)) {
var strings = _strings;
if (strings == null) _strings = strings = _newHashTable();
- _addHashTableEntry(strings, element);
+ return _addHashTableEntry(strings, element);
} else if (_isNumericElement(element)) {
var nums = _nums;
if (nums == null) _nums = nums = _newHashTable();
- _addHashTableEntry(nums, element);
+ return _addHashTableEntry(nums, element);
} else {
var rest = _rest;
if (rest == null) _rest = rest = _newHashTable();
@@ -1020,11 +1020,12 @@ class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> {
_setTableEntry(rest, hash, JS('var', '[#]', element));
} else {
int index = _findBucketIndex(bucket, element);
- if (index >= 0) return;
+ if (index >= 0) return false;
JS('void', '#.push(#)', bucket, element);
}
_length++;
_elements = null;
+ return true;
}
}
@@ -1131,11 +1132,12 @@ class _HashSet<E> extends _HashSetBase<E> implements HashSet<E> {
return _elements = result;
}
- void _addHashTableEntry(var table, E element) {
- if (_hasTableEntry(table, element)) return;
+ bool _addHashTableEntry(var table, E element) {
+ if (_hasTableEntry(table, element)) return false;
_setTableEntry(table, element, 0);
_length++;
_elements = null;
+ return true;
}
bool _removeHashTableEntry(var table, Object element) {
@@ -1456,15 +1458,15 @@ class _LinkedHashSet<E> extends _HashSetBase<E> implements LinkedHashSet<E> {
}
// Collection.
- void add(E element) {
+ bool add(E element) {
if (_isStringElement(element)) {
var strings = _strings;
if (strings == null) _strings = strings = _newHashTable();
- _addHashTableEntry(strings, element);
+ return _addHashTableEntry(strings, element);
} else if (_isNumericElement(element)) {
var nums = _nums;
if (nums == null) _nums = nums = _newHashTable();
- _addHashTableEntry(nums, element);
+ return _addHashTableEntry(nums, element);
} else {
var rest = _rest;
if (rest == null) _rest = rest = _newHashTable();
@@ -1475,10 +1477,11 @@ class _LinkedHashSet<E> extends _HashSetBase<E> implements LinkedHashSet<E> {
_setTableEntry(rest, hash, JS('var', '[#]', cell));
} else {
int index = _findBucketIndex(bucket, element);
- if (index >= 0) return;
+ if (index >= 0) return false;
LinkedHashSetCell cell = _newLinkedCell(element);
JS('void', '#.push(#)', bucket, cell);
}
+ return true;
}
}
@@ -1548,10 +1551,11 @@ class _LinkedHashSet<E> extends _HashSetBase<E> implements LinkedHashSet<E> {
}
}
- void _addHashTableEntry(var table, E element) {
+ bool _addHashTableEntry(var table, E element) {
LinkedHashSetCell cell = _getTableEntry(table, element);
- if (cell != null) return;
+ if (cell != null) return false;
_setTableEntry(table, element, _newLinkedCell(element));
+ return true;
}
bool _removeHashTableEntry(var table, Object element) {
« no previous file with comments | « runtime/lib/collection_patch.dart ('k') | sdk/lib/core/set.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698