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

Unified Diff: sdk/lib/core/uri.dart

Issue 1425373005: Don't copy text in _uriEncode if not necessary. Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 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 | « sdk/lib/core/core.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index 10aa827cb190c6e93a8889cad67312629145d5f5..944c8d38cb4c84624ec05278dca0a1e019512d74 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -2260,26 +2260,40 @@ class Uri {
String text,
{Encoding encoding: UTF8,
bool spaceToPlus: false}) {
- byteToHex(byte, buffer) {
- const String hex = '0123456789ABCDEF';
- buffer.writeCharCode(hex.codeUnitAt(byte >> 4));
- buffer.writeCharCode(hex.codeUnitAt(byte & 0x0f));
- }
-
- // Encode the string into bytes then generate an ASCII only string
- // by percent encoding selected bytes.
- StringBuffer result = new StringBuffer();
var bytes = encoding.encode(text);
+ StringBuffer result;
+ int start = 0;
for (int i = 0; i < bytes.length; i++) {
int byte = bytes[i];
if (byte < 128 &&
((canonicalTable[byte >> 4] & (1 << (byte & 0x0f))) != 0)) {
- result.writeCharCode(byte);
- } else if (spaceToPlus && byte == _SPACE) {
+ continue;
+ }
+ result ??= new StringBuffer();
+ for (int j = start; j < i; j++) {
+ result.writeCharCode(bytes[j]);
+ }
+ if (spaceToPlus && byte == _SPACE) {
result.writeCharCode(_PLUS);
} else {
result.writeCharCode(_PERCENT);
- byteToHex(byte, result);
+ const String hex = '0123456789ABCDEF';
+ result.writeCharCode(hex.codeUnitAt(byte >> 4));
+ result.writeCharCode(hex.codeUnitAt(byte & 0x0f));
+ }
+ start = i + 1;
+ }
+ if (result == null) {
+ if (identical(encoding, ASCII) ||
+ identical(encoding, LATIN1) ||
+ identical(encoding, UTF8)) {
+ return text;
+ }
+ return new String.fromCharCodes(bytes);
+ }
+ if (start < bytes.length) {
+ for (int j = start; j < bytes.length; j++) {
+ result.writeCharCode(bytes[j]);
}
}
return result.toString();
« no previous file with comments | « sdk/lib/core/core.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698