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

Unified Diff: sdk/lib/io/http_headers.dart

Issue 246833003: Revert "Remove unmodifiable map wrappers that could instead use UnmodifiableMapView." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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 | « sdk/lib/core/uri.dart ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/http_headers.dart
diff --git a/sdk/lib/io/http_headers.dart b/sdk/lib/io/http_headers.dart
index 587910647ff75b068daa602e067346fe9b821291..5dd5c55fd064e50f44e9c3e7d43047a2c3dc0518 100644
--- a/sdk/lib/io/http_headers.dart
+++ b/sdk/lib/io/http_headers.dart
@@ -523,12 +523,12 @@ class _HttpHeaders implements HttpHeaders {
class _HeaderValue implements HeaderValue {
String _value;
- Map<String, String> _parameters;
- Map<String, String> _unmodifiableParameters;
+ _UnmodifiableMap<String, String> _parameters;
_HeaderValue([String this._value = "", Map<String, String> parameters]) {
if (parameters != null) {
- _parameters = new HashMap<String, String>.from(parameters);
+ _parameters =
+ new _UnmodifiableMap(new HashMap<String, String>.from(parameters));
}
}
@@ -545,16 +545,13 @@ class _HeaderValue implements HeaderValue {
void _ensureParameters() {
if (_parameters == null) {
- _parameters = new HashMap<String, String>();
+ _parameters = new _UnmodifiableMap(new HashMap<String, String>());
}
}
Map<String, String> get parameters {
_ensureParameters();
- if (_unmodifiableParameters == null) {
- _unmodifiableParameters = new UnmodifiableMapView(_parameters);
- }
- return _unmodifiableParameters;
+ return _parameters;
}
String toString() {
@@ -604,7 +601,7 @@ class _HeaderValue implements HeaderValue {
void parseParameters() {
var parameters = new HashMap<String, String>();
- _parameters = new UnmodifiableMapView(parameters);
+ _parameters = new _UnmodifiableMap(parameters);
String parseParameterName() {
int start = index;
@@ -683,12 +680,12 @@ class _ContentType extends _HeaderValue implements ContentType {
if (parameters != null) {
_ensureParameters();
parameters.forEach((String key, String value) {
- this._parameters[key.toLowerCase()] = value.toLowerCase();
+ this._parameters._map[key.toLowerCase()] = value.toLowerCase();
});
}
if (charset != null) {
_ensureParameters();
- this._parameters["charset"] = charset.toLowerCase();
+ this._parameters._map["charset"] = charset.toLowerCase();
}
}
@@ -871,3 +868,34 @@ class _Cookie implements Cookie {
}
}
}
+
+
+class _UnmodifiableMap<K, V> implements Map<K, V> {
+ final Map _map;
+ const _UnmodifiableMap(this._map);
+
+ bool containsValue(Object value) => _map.containsValue(value);
+ bool containsKey(Object key) => _map.containsKey(key);
+ V operator [](Object key) => _map[key];
+ void operator []=(K key, V value) {
+ throw new UnsupportedError("Cannot modify an unmodifiable map");
+ }
+ V putIfAbsent(K key, V ifAbsent()) {
+ throw new UnsupportedError("Cannot modify an unmodifiable map");
+ }
+ addAll(Map other) {
+ throw new UnsupportedError("Cannot modify an unmodifiable map");
+ }
+ V remove(Object key) {
+ throw new UnsupportedError("Cannot modify an unmodifiable map");
+ }
+ void clear() {
+ throw new UnsupportedError("Cannot modify an unmodifiable map");
+ }
+ void forEach(void f(K key, V value)) => _map.forEach(f);
+ Iterable<K> get keys => _map.keys;
+ Iterable<V> get values => _map.values;
+ int get length => _map.length;
+ bool get isEmpty => _map.isEmpty;
+ bool get isNotEmpty => _map.isNotEmpty;
+}
« no previous file with comments | « sdk/lib/core/uri.dart ('k') | sdk/lib/io/io.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698