Chromium Code Reviews| Index: lib/src/shelf_unmodifiable_map.dart |
| diff --git a/lib/src/shelf_unmodifiable_map.dart b/lib/src/shelf_unmodifiable_map.dart |
| index d07ebfd59635248f2e1dc74623d3daeb3d7174cc..1d9c09739cf992b92d5b532f15a86e88805c7e50 100644 |
| --- a/lib/src/shelf_unmodifiable_map.dart |
| +++ b/lib/src/shelf_unmodifiable_map.dart |
| @@ -6,11 +6,15 @@ library shelf.shelf_unmodifiable_map; |
| import 'dart:collection'; |
| -import 'package:collection/wrappers.dart' as pc; |
| +import 'package:http_parser/http_parser.dart'; |
| -/// A simple wrapper over [pc.UnmodifiableMapView] which avoids re-wrapping |
| -/// itself. |
| +// TODO(kevmoo): Get rid of this once we get something like |
| +// https://codereview.chromium.org/1319783003/ |
|
nweiz
2015/10/20 21:06:50
Will we be able to preserve case-insensitivity wit
kevmoo
2015/10/21 00:17:17
perhaps not
|
| +/// A simple wrapper over [UnmodifiableMapView] which avoids re-wrapping itself. |
| class ShelfUnmodifiableMap<V> extends UnmodifiableMapView<String, V> { |
| + /// `true` if the key values are already lowercase. |
| + final bool ignoreKeyCase; |
|
nweiz
2015/10/20 21:06:50
Why is this public?
kevmoo
2015/10/21 00:17:17
same reason ShelfUnmodifiableMap is public – but i
nweiz
2015/10/21 00:19:21
ShelfUnmodifiableMap is public because it needs to
|
| + |
| /// If [source] is a [ShelfUnmodifiableMap] with matching [ignoreKeyCase], |
| /// then [source] is returned. |
| /// |
| @@ -22,7 +26,10 @@ class ShelfUnmodifiableMap<V> extends UnmodifiableMapView<String, V> { |
| /// after constructions are not reflected. |
| factory ShelfUnmodifiableMap(Map<String, V> source, |
| {bool ignoreKeyCase: false}) { |
| - if (source is ShelfUnmodifiableMap<V>) { |
| + if (source is ShelfUnmodifiableMap<V> && |
| + // !ignoreKeyCase: no transformation of the input is required |
| + // source.ignoreKeyCase: the input cannot be transformed any more |
| + (!ignoreKeyCase || source.ignoreKeyCase)) { |
| return source; |
| } |
| @@ -31,22 +38,21 @@ class ShelfUnmodifiableMap<V> extends UnmodifiableMapView<String, V> { |
| } |
| if (ignoreKeyCase) { |
| - source = new pc.CanonicalizedMap<String, String, V>.from( |
| - source, (key) => key.toLowerCase(), isValidKey: (key) => key != null); |
| + source = new CaseInsensitiveMap<V>.from(source); |
| } else { |
| source = new Map<String, V>.from(source); |
| } |
| - return new ShelfUnmodifiableMap<V>._(source); |
| + return new ShelfUnmodifiableMap<V>._(source, ignoreKeyCase); |
| } |
| - ShelfUnmodifiableMap._(Map<String, V> source) : super(source); |
| + ShelfUnmodifiableMap._(Map<String, V> source, this.ignoreKeyCase) |
| + : super(source); |
| } |
| -/// An const empty implementation of [ShelfUnmodifiableMap]. |
| -// TODO(kevmoo): Consider using MapView from dart:collection which has a const |
| -// ctor. Would require updating min SDK to 1.5. |
| -class _EmptyShelfUnmodifiableMap<V> extends pc.DelegatingMap<String, V> |
| +/// A const implementation of an empty [ShelfUnmodifiableMap]. |
| +class _EmptyShelfUnmodifiableMap<V> extends MapView<String, V> |
| implements ShelfUnmodifiableMap<V> { |
| + bool get ignoreKeyCase => true; |
| const _EmptyShelfUnmodifiableMap() : super(const {}); |
| } |