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

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

Issue 1428163002: Short-circuit Uri._uriEncode for components that don't need encoding. 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 | « 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/core/uri.dart
diff --git a/sdk/lib/core/uri.dart b/sdk/lib/core/uri.dart
index 10aa827cb190c6e93a8889cad67312629145d5f5..3c458358d690fe9bf723fd914764e049efde4d85 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -2260,6 +2260,8 @@ class Uri {
String text,
{Encoding encoding: UTF8,
bool spaceToPlus: false}) {
+ if (_noUriEncodingNeeded(canonicalTable, text, encoding)) return text;
+
byteToHex(byte, buffer) {
const String hex = '0123456789ABCDEF';
buffer.writeCharCode(hex.codeUnitAt(byte >> 4));
@@ -2285,6 +2287,17 @@ class Uri {
return result.toString();
}
+ static bool _noUriEncodingNeeded(
+ List<int> canonicalTable, String text, Encoding encoding) {
+ if (encoding != UTF8) return false;
+ for (int i = 0; i < text.length; i++) {
+ int code = text.codeUnitAt(i);
+ if (code >= 128) return false;
+ if ((canonicalTable[code >> 4] & (1 << (code & 0x0f))) == 0) return false;
+ }
+ return true;
+ }
+
/**
* Convert a byte (2 character hex sequence) in string [s] starting
* at position [pos] to its ordinal 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