| 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();
|
|
|