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

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

Issue 173683002: Slightly speed up http-parser and http-header-writing. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Limit status code length. Created 6 years, 10 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 | sdk/lib/io/http_impl.dart » ('j') | 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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 int _write(Uint8List buffer, int offset) { 389 int _write(Uint8List buffer, int offset) {
390 void write(List<int> bytes) { 390 void write(List<int> bytes) {
391 int len = bytes.length; 391 int len = bytes.length;
392 for (int i = 0; i < len; i++) { 392 for (int i = 0; i < len; i++) {
393 buffer[offset + i] = bytes[i]; 393 buffer[offset + i] = bytes[i];
394 } 394 }
395 offset += len; 395 offset += len;
396 } 396 }
397 397
398 // Format headers. 398 // Format headers.
399 _headers.forEach((String name, List<String> values) { 399 for (String name in _headers.keys) {
400 List<String> values = _headers[name];
400 bool fold = _foldHeader(name); 401 bool fold = _foldHeader(name);
401 var nameData = name.codeUnits; 402 var nameData = name.codeUnits;
402 write(nameData); 403 write(nameData);
403 write(const [_CharCode.COLON, _CharCode.SP]); 404 buffer[offset++] = _CharCode.COLON;
405 buffer[offset++] = _CharCode.SP;
404 for (int i = 0; i < values.length; i++) { 406 for (int i = 0; i < values.length; i++) {
405 if (i > 0) { 407 if (i > 0) {
406 if (fold) { 408 if (fold) {
407 write(const [_CharCode.COMMA, _CharCode.SP]); 409 buffer[offset++] = _CharCode.COMMA;
410 buffer[offset++] = _CharCode.SP;
408 } else { 411 } else {
409 write(const [_CharCode.CR, _CharCode.LF]); 412 buffer[offset++] = _CharCode.CR;
413 buffer[offset++] = _CharCode.LF;
410 write(nameData); 414 write(nameData);
411 write(const [_CharCode.COLON, _CharCode.SP]); 415 buffer[offset++] = _CharCode.COLON;
416 buffer[offset++] = _CharCode.SP;
412 } 417 }
413 } 418 }
414 write(values[i].codeUnits); 419 write(values[i].codeUnits);
415 } 420 }
416 write(const [_CharCode.CR, _CharCode.LF]); 421 buffer[offset++] = _CharCode.CR;
417 }); 422 buffer[offset++] = _CharCode.LF;
423 }
418 return offset; 424 return offset;
419 } 425 }
420 426
421 String toString() { 427 String toString() {
422 StringBuffer sb = new StringBuffer(); 428 StringBuffer sb = new StringBuffer();
423 _headers.forEach((String name, List<String> values) { 429 _headers.forEach((String name, List<String> values) {
424 sb..write(name)..write(": "); 430 sb..write(name)..write(": ");
425 bool fold = _foldHeader(name); 431 bool fold = _foldHeader(name);
426 for (int i = 0; i < values.length; i++) { 432 for (int i = 0; i < values.length; i++) {
427 if (i > 0) { 433 if (i > 0) {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 void clear() { 855 void clear() {
850 throw new UnsupportedError("Cannot modify an unmodifiable map"); 856 throw new UnsupportedError("Cannot modify an unmodifiable map");
851 } 857 }
852 void forEach(void f(K key, V value)) => _map.forEach(f); 858 void forEach(void f(K key, V value)) => _map.forEach(f);
853 Iterable<K> get keys => _map.keys; 859 Iterable<K> get keys => _map.keys;
854 Iterable<V> get values => _map.values; 860 Iterable<V> get values => _map.values;
855 int get length => _map.length; 861 int get length => _map.length;
856 bool get isEmpty => _map.isEmpty; 862 bool get isEmpty => _map.isEmpty;
857 bool get isNotEmpty => _map.isNotEmpty; 863 bool get isNotEmpty => _map.isNotEmpty;
858 } 864 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/io/http_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698