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

Unified Diff: lib/src/shelf_unmodifiable_map.dart

Issue 1413933003: pkg/shelf: Use CaseInsensitiveMap from pkg/http_handler (Closed) Base URL: https://github.com/dart-lang/shelf.git@master
Patch Set: nit Created 5 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 | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..46b422347475fd50d392fb1c9060ee525d5b0b76 100644
--- a/lib/src/shelf_unmodifiable_map.dart
+++ b/lib/src/shelf_unmodifiable_map.dart
@@ -6,11 +6,13 @@ 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.
+/// 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;
+
/// If [source] is a [ShelfUnmodifiableMap] with matching [ignoreKeyCase],
/// then [source] is returned.
///
@@ -22,7 +24,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 +36,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 {});
}
« no previous file with comments | « CHANGELOG.md ('k') | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698