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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | 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 33d51373a121331ab282ca78dcb6a0916ccfe185..14a34853bee0577b262987823dd1bca903dae153 100644
--- a/sdk/lib/io/http_headers.dart
+++ b/sdk/lib/io/http_headers.dart
@@ -338,25 +338,53 @@ class _HttpHeaders implements HttpHeaders {
headers._set(HttpHeaders.CONTENT_TYPE, value);
}
- // TODO(ajohnsen): Change to const map, once const maps are faster.
- static final _addMap = {
- HttpHeaders.CONTENT_LENGTH: _addContentLength,
- HttpHeaders.TRANSFER_ENCODING: _addTransferEncoding,
- HttpHeaders.DATE: _addDate,
- HttpHeaders.EXPIRES: _addExpires,
- HttpHeaders.IF_MODIFIED_SINCE: _addIfModifiedSince,
- HttpHeaders.HOST: _addHost,
- HttpHeaders.CONNECTION: _addConnection,
- HttpHeaders.CONTENT_TYPE: _addContentType
- };
-
// [name] must be a lower-case version of the name.
void _add(String name, value) {
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.
- var method = _addMap[name];
- if (method != null) {
- method(this, name, value);
- return;
+ switch (name.length) {
+ case 4:
+ if (HttpHeaders.DATE == name) {
+ _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.
+ return;
+ }
+ if (HttpHeaders.HOST == name) {
+ _addHost(this, name, value);
+ return;
+ }
+ break;
+ case 7:
+ if (HttpHeaders.EXPIRES == name) {
+ _addExpires(this, name, value);
+ return;
+ }
+ break;
+ case 10:
+ if (HttpHeaders.CONNECTION == name) {
+ _addConnection(this, name, value);
+ return;
+ }
+ break;
+ case 12:
+ if (HttpHeaders.CONTENT_TYPE == name) {
+ _addContentType(this, name, value);
+ return;
+ }
+ break;
+ case 14:
+ if (HttpHeaders.CONTENT_LENGTH == name) {
+ _addContentLength(this, name, value);
+ return;
+ }
+ break;
+ case 17:
+ if (HttpHeaders.TRANSFER_ENCODING == name) {
+ _addTransferEncoding(this, name, value);
+ return;
+ }
+ if (HttpHeaders.IF_MODIFIED_SINCE == name) {
+ _addIfModifiedSince(this, name, value);
+ return;
+ }
}
_addValue(name, value);
}
« 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