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

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

Issue 80883002: Avoid unneeded toLowerCase and add fast version of _isTokenChar, in HTTP parser. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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
« sdk/lib/io/http_headers.dart ('K') | « sdk/lib/io/http_impl.dart ('k') | 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 // Global constants. 7 // Global constants.
8 class _Const { 8 class _Const {
9 // Bytes for "HTTP". 9 // Bytes for "HTTP".
10 static const HTTP = const [72, 84, 84, 80]; 10 static const HTTP = const [72, 84, 84, 80];
11 // Bytes for "HTTP/1.". 11 // Bytes for "HTTP/1.".
12 static const HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46]; 12 static const HTTP1DOT = const [72, 84, 84, 80, 47, 49, 46];
13 // Bytes for "HTTP/1.0". 13 // Bytes for "HTTP/1.0".
14 static const HTTP10 = const [72, 84, 84, 80, 47, 49, 46, 48]; 14 static const HTTP10 = const [72, 84, 84, 80, 47, 49, 46, 48];
15 // Bytes for "HTTP/1.1". 15 // Bytes for "HTTP/1.1".
16 static const HTTP11 = const [72, 84, 84, 80, 47, 49, 46, 49]; 16 static const HTTP11 = const [72, 84, 84, 80, 47, 49, 46, 49];
17 17
18 static const END_CHUNKED = const [0x30, 13, 10, 13, 10]; 18 static const END_CHUNKED = const [0x30, 13, 10, 13, 10];
19 19
20 // Bytes for '()<>@,;:\\"/[]?={} \t'. 20 // Bytes for '()<>@,;:\\"/[]?={} \t'.
21 static const SEPARATORS = const [40, 41, 60, 62, 64, 44, 59, 58, 92, 34, 47, 21 static const SEPARATORS = const [40, 41, 60, 62, 64, 44, 59, 58, 92, 34, 47,
Søren Gjesse 2013/11/21 13:03:03 Is SEPARATORS still used?
Anders Johnsen 2013/11/21 13:14:41 Done.
22 91, 93, 63, 61, 123, 125, 32, 9]; 22 91, 93, 63, 61, 123, 125, 32, 9];
23 23
24 // Loopup-map for _isTokenChar.
Søren Gjesse 2013/11/21 13:03:03 Add the character-list from above to the comment.
Anders Johnsen 2013/11/21 13:14:41 Done.
25 static const CHAR_MAP = const [
Søren Gjesse 2013/11/21 13:03:03 CHAR_MAP -> TOKEN_CHAR_MAP
Anders Johnsen 2013/11/21 13:14:41 Done.
26 false,false,false,false,false,false,false,false,false,false,false,false,
27 false,false,false,false,false,false,false,false,false,false,false,false,
28 false,false,false,false,false,false,false,false,false,true,false,true,
29 true,true,true,true,false,false,true,true,false,true,true,false,true,true,
30 true,true,true,true,true,true,true,true,false,false,false,false,false,
31 false,false,true,true,true,true,true,true,true,true,true,true,true,true,
32 true,true,true,true,true,true,true,true,true,true,true,true,true,true,
33 false,false,false,true,true,true,true,true,true,true,true,true,true,true,
34 true,true,true,true,true,true,true,true,true,true,true,true,true,true,
35 true,true,true,true,false,true,false,true,true,false,false,false,false,
36 false,false,false,false,false,false,false,false,false,false,false,false,
37 false,false,false,false,false,false,false,false,false,false,false,false,
38 false,false,false,false,false,false,false,false,false,false,false,false,
39 false,false,false,false,false,false,false,false,false,false,false,false,
40 false,false,false,false,false,false,false,false,false,false,false,false,
41 false,false,false,false,false,false,false,false,false,false,false,false,
42 false,false,false,false,false,false,false,false,false,false,false,false,
43 false,false,false,false,false,false,false,false,false,false,false,false,
44 false,false,false,false,false,false,false,false,false,false,false,false,
45 false,false,false,false,false,false,false,false,false,false,false,false,
46 false,false,false,false];
47
24 // Bytes for '()<>@,;:\\"/[]?={} \t\r\n'. 48 // Bytes for '()<>@,;:\\"/[]?={} \t\r\n'.
25 static const SEPARATORS_AND_CR_LF = const [40, 41, 60, 62, 64, 44, 59, 58, 92, 49 static const SEPARATORS_AND_CR_LF = const [40, 41, 60, 62, 64, 44, 59, 58, 92,
26 34, 47, 91, 93, 63, 61, 123, 125, 50 34, 47, 91, 93, 63, 61, 123, 125,
27 32, 9, 13, 10]; 51 32, 9, 13, 10];
28 } 52 }
29 53
30 54
31 // Frequently used character codes. 55 // Frequently used character codes.
32 class _CharCode { 56 class _CharCode {
33 static const int HT = 9; 57 static const int HT = 9;
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 _remainingContent = -1; 852 _remainingContent = -1;
829 853
830 _headers = null; 854 _headers = null;
831 } 855 }
832 856
833 _releaseBuffer() { 857 _releaseBuffer() {
834 _buffer = null; 858 _buffer = null;
835 _index = null; 859 _index = null;
836 } 860 }
837 861
838 bool _isTokenChar(int byte) { 862 bool _isTokenChar(int byte) => _Const.CHAR_MAP[byte];
839 return byte > 31 && byte < 128 && _Const.SEPARATORS.indexOf(byte) == -1;
840 }
841 863
842 List<String> _tokenizeFieldValue(String headerValue) { 864 List<String> _tokenizeFieldValue(String headerValue) {
843 List<String> tokens = new List<String>(); 865 List<String> tokens = new List<String>();
844 int start = 0; 866 int start = 0;
845 int index = 0; 867 int index = 0;
846 while (index < headerValue.length) { 868 while (index < headerValue.length) {
847 if (headerValue[index] == ",") { 869 if (headerValue[index] == ",") {
848 tokens.add(headerValue.substring(start, index)); 870 tokens.add(headerValue.substring(start, index));
849 start = index + 1; 871 start = index + 1;
850 } else if (headerValue[index] == " " || headerValue[index] == "\t") { 872 } else if (headerValue[index] == " " || headerValue[index] == "\t") {
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 _HttpHeaders _headers; 1005 _HttpHeaders _headers;
984 1006
985 // The current incoming connection. 1007 // The current incoming connection.
986 _HttpIncoming _incoming; 1008 _HttpIncoming _incoming;
987 StreamSubscription _socketSubscription; 1009 StreamSubscription _socketSubscription;
988 bool _paused = true; 1010 bool _paused = true;
989 bool _bodyPaused = false; 1011 bool _bodyPaused = false;
990 StreamController<_HttpIncoming> _controller; 1012 StreamController<_HttpIncoming> _controller;
991 StreamController<List<int>> _bodyController; 1013 StreamController<List<int>> _bodyController;
992 } 1014 }
OLDNEW
« sdk/lib/io/http_headers.dart ('K') | « sdk/lib/io/http_impl.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698