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

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

Issue 11413010: Collect the HTTP header in a byte buffer and send it all at once. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month 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_impl.dart
diff --git a/sdk/lib/io/http_impl.dart b/sdk/lib/io/http_impl.dart
index 19adf28b06bf2377ee4197f1250f8213690f9d5a..e61fcc28626da13167c9a1648d6335d9ebaf68d9 100644
--- a/sdk/lib/io/http_impl.dart
+++ b/sdk/lib/io/http_impl.dart
@@ -249,29 +249,51 @@ class _HttpHeaders implements HttpHeaders {
final COMMASP = const [_CharCode.COMMA, _CharCode.SP];
final CRLF = const [_CharCode.CR, _CharCode.LF];
+ var bufferSize = 16 * 1024;
+ var buffer = new Uint8List(bufferSize);
+ var bufferPos = 0;
+
+ void writeBuffer() {
+ connection._writeFrom(buffer, 0, bufferPos);
+ bufferPos = 0;
+ }
+
// Format headers.
_headers.forEach((String name, List<String> values) {
bool fold = _foldHeader(name);
- List<int> data;
- data = name.charCodes;
- connection._write(data);
- connection._write(COLONSP);
+ List<int> nameData;
+ nameData = name.charCodes;
+ int nameDataLen = nameData.length;
+ if (nameDataLen + 2 > bufferSize - bufferPos) writeBuffer();
+ buffer.setRange(bufferPos, nameDataLen, nameData);
+ bufferPos += nameDataLen;
+ buffer[bufferPos++] = _CharCode.COLON;
+ buffer[bufferPos++] = _CharCode.SP;
for (int i = 0; i < values.length; i++) {
+ List<int> data = values[i].charCodes;
+ int dataLen = data.length;
+ // Worst case here is writing the name, value and 6 additional bytes.
+ if (nameDataLen + dataLen + 6 > bufferSize - bufferPos) writeBuffer();
if (i > 0) {
if (fold) {
- connection._write(COMMASP);
+ buffer[bufferPos++] = _CharCode.COMMA;
+ buffer[bufferPos++] = _CharCode.SP;
} else {
- connection._write(CRLF);
- data = name.charCodes;
- connection._write(data);
- connection._write(COLONSP);
+ buffer[bufferPos++] = _CharCode.CR;
+ buffer[bufferPos++] = _CharCode.LF;
+ buffer.setRange(bufferPos, nameDataLen, nameData);
+ bufferPos += nameDataLen;
+ buffer[bufferPos++] = _CharCode.COLON;
+ buffer[bufferPos++] = _CharCode.SP;
}
}
- data = values[i].charCodes;
- connection._write(data);
+ buffer.setRange(bufferPos, dataLen, data);
+ bufferPos += dataLen;
}
- connection._write(CRLF);
+ buffer[bufferPos++] = _CharCode.CR;
+ buffer[bufferPos++] = _CharCode.LF;
});
+ writeBuffer();
}
String toString() {
« 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