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

Side by Side Diff: sdk/lib/io/http_headers.dart

Issue 249083004: Int switch (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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of dart.io; 5 part of dart.io;
6 6
7 class _HttpHeaders implements HttpHeaders { 7 class _HttpHeaders implements HttpHeaders {
8 final Map<String, List<String>> _headers; 8 final Map<String, List<String>> _headers;
9 final String protocolVersion; 9 final String protocolVersion;
10 10
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } else if (lowerCaseValue == 'keep-alive') { 331 } else if (lowerCaseValue == 'keep-alive') {
332 headers._persistentConnection = true; 332 headers._persistentConnection = true;
333 } 333 }
334 headers._addValue(name, value); 334 headers._addValue(name, value);
335 } 335 }
336 336
337 static void _addContentType(_HttpHeaders headers, String name, value) { 337 static void _addContentType(_HttpHeaders headers, String name, value) {
338 headers._set(HttpHeaders.CONTENT_TYPE, value); 338 headers._set(HttpHeaders.CONTENT_TYPE, value);
339 } 339 }
340 340
341 // TODO(ajohnsen): Change to const map, once const maps are faster.
342 static final _addMap = {
343 HttpHeaders.CONTENT_LENGTH: _addContentLength,
344 HttpHeaders.TRANSFER_ENCODING: _addTransferEncoding,
345 HttpHeaders.DATE: _addDate,
346 HttpHeaders.EXPIRES: _addExpires,
347 HttpHeaders.IF_MODIFIED_SINCE: _addIfModifiedSince,
348 HttpHeaders.HOST: _addHost,
349 HttpHeaders.CONNECTION: _addConnection,
350 HttpHeaders.CONTENT_TYPE: _addContentType
351 };
352
353 // [name] must be a lower-case version of the name. 341 // [name] must be a lower-case version of the name.
354 void _add(String name, value) { 342 void _add(String name, value) {
355 assert(name == name.toLowerCase()); 343 assert(name == name.toLowerCase());
Søren Gjesse 2014/04/23 12:06:39 Please add a comment on this optimization.
Anders Johnsen 2014/04/23 12:20:12 Done.
356 var method = _addMap[name]; 344 switch (name.length) {
357 if (method != null) { 345 case 4:
358 method(this, name, value); 346 if (HttpHeaders.DATE == name) {
359 return; 347 _addDate(this, name, value);
Anders Johnsen 2014/04/23 11:57:05 Should we merge return into this line?
Søren Gjesse 2014/04/23 12:06:39 Don't think so.
348 return;
349 }
350 if (HttpHeaders.HOST == name) {
351 _addHost(this, name, value);
352 return;
353 }
354 break;
355 case 7:
356 if (HttpHeaders.EXPIRES == name) {
357 _addExpires(this, name, value);
358 return;
359 }
360 break;
361 case 10:
362 if (HttpHeaders.CONNECTION == name) {
363 _addConnection(this, name, value);
364 return;
365 }
366 break;
367 case 12:
368 if (HttpHeaders.CONTENT_TYPE == name) {
369 _addContentType(this, name, value);
370 return;
371 }
372 break;
373 case 14:
374 if (HttpHeaders.CONTENT_LENGTH == name) {
375 _addContentLength(this, name, value);
376 return;
377 }
378 break;
379 case 17:
380 if (HttpHeaders.TRANSFER_ENCODING == name) {
381 _addTransferEncoding(this, name, value);
382 return;
383 }
384 if (HttpHeaders.IF_MODIFIED_SINCE == name) {
385 _addIfModifiedSince(this, name, value);
386 return;
387 }
360 } 388 }
361 _addValue(name, value); 389 _addValue(name, value);
362 } 390 }
363 391
364 void _addValue(String name, Object value) { 392 void _addValue(String name, Object value) {
365 List<String> values = _headers[name]; 393 List<String> values = _headers[name];
366 if (values == null) { 394 if (values == null) {
367 values = new List<String>(); 395 values = new List<String>();
368 _headers[name] = values; 396 _headers[name] = values;
369 } 397 }
(...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 void clear() { 934 void clear() {
907 throw new UnsupportedError("Cannot modify an unmodifiable map"); 935 throw new UnsupportedError("Cannot modify an unmodifiable map");
908 } 936 }
909 void forEach(void f(K key, V value)) => _map.forEach(f); 937 void forEach(void f(K key, V value)) => _map.forEach(f);
910 Iterable<K> get keys => _map.keys; 938 Iterable<K> get keys => _map.keys;
911 Iterable<V> get values => _map.values; 939 Iterable<V> get values => _map.values;
912 int get length => _map.length; 940 int get length => _map.length;
913 bool get isEmpty => _map.isEmpty; 941 bool get isEmpty => _map.isEmpty;
914 bool get isNotEmpty => _map.isNotEmpty; 942 bool get isNotEmpty => _map.isNotEmpty;
915 } 943 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698