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

Unified Diff: runtime/lib/string_patch.dart

Issue 212423003: Optimize String.fromCharCode. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Shortcut List creation. Created 6 years, 9 months 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 | sdk/lib/_internal/lib/core_patch.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/lib/string_patch.dart
diff --git a/runtime/lib/string_patch.dart b/runtime/lib/string_patch.dart
index 717e49db71984f56878bbfcf0cde617c7efb3be5..ee8a12ab8f9a6e0aab32ade4e891fa5f39b4739d 100644
--- a/runtime/lib/string_patch.dart
+++ b/runtime/lib/string_patch.dart
@@ -7,6 +7,25 @@ patch class String {
return _StringBase.createFromCharCodes(charCodes);
}
+ /* patch */ factory String.fromCharCode(int charCode) {
+ if (charCode >= 0) {
+ if (charCode <= 0xff) {
+ return _OneByteString._allocate(1).._setAt(0, charCode);
+ }
+ if (charCode <= 0xffff) {
+ return _StringBase._createFromCodePoints(new _List(1)..[0] = charCode);
+ }
+ if (charCode <= 0x10ffff) {
+ var low = 0xDC00 | (charCode & 0x3ff);
+ int bits = charCode - 0x10000;
+ var high = 0xD800 | (bits >> 10);
+ return _StringBase._createFromCodePoints(new _List(2)..[0] = high
+ ..[1] = low);
+ }
+ }
+ throw new RangeError.range(charCode, 0, 0x10ffff);
+ }
+
/* patch */ const factory String.fromEnvironment(String name,
{String defaultValue})
native "String_fromEnvironment";
« no previous file with comments | « no previous file | sdk/lib/_internal/lib/core_patch.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698