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

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

Issue 1411413008: Short-circuit Uri._uriEncode for components that don't need encoding. (Closed) 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..6955f5ccba6c3f2e1b3a6b2d2af9fada12f70ec9 100644
--- a/sdk/lib/core/uri.dart
+++ b/sdk/lib/core/uri.dart
@@ -2251,6 +2251,10 @@ class Uri {
static const int _LOWER_CASE_Z = 0x7A;
static const int _BAR = 0x7C;
+ // Matches a String that _uriEncodes to itself regardless of the kind of
+ // component. This corresponds to [_unreservedTable].
+ static final RegExp _needsNoEncoding = new RegExp(r'^[\-\.0-9A-Z_a-z~]*$');
Ivan Posva 2015/11/04 05:11:50 Please refrain from using RegExp in core library c
+
/**
* This is the internal implementation of JavaScript's encodeURI function.
* It encodes all characters in the string [text] except for those
@@ -2260,6 +2264,8 @@ class Uri {
String text,
{Encoding encoding: UTF8,
bool spaceToPlus: false}) {
+ if (_needsNoEncoding.hasMatch(text)) return text;
Lasse Reichstein Nielsen 2015/11/03 07:08:19 This should be a regexp that matches canonicalTabl
Lasse Reichstein Nielsen 2015/11/03 07:12:08 Ah, finally realized that the only characters used
Lasse Reichstein Nielsen 2015/11/04 08:32:41 Only do this if encoding is UTF8, LATIN1 or ASCII
+
byteToHex(byte, buffer) {
const String hex = '0123456789ABCDEF';
buffer.writeCharCode(hex.codeUnitAt(byte >> 4));
« 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