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

Unified Diff: src/heap.cc

Issue 11469014: Add a safe API for creating ASCII-only strings
Patch Set: Created 8 years 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 | « src/heap.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index dac28f34b22636ca359851615926a9e111bf258d..6dd83d422587ace5824f45db0fb96eab0e44909d 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -4534,6 +4534,28 @@ MaybeObject* Heap::AllocateStringFromOneByte(Vector<const char> string,
}
+MaybeObject* Heap::AllocateStringFromAsciiSafe(Vector<const char> string,
+ PretenureFlag pretenure) {
+ if (string.length() == 1) {
+ return Heap::LookupSingleCharacterStringFromCode(string
+ [0] & String::kMaxAsciiCharCodeU);
+ }
+ Object* result;
+ { MaybeObject* maybe_result =
+ AllocateRawAsciiString(string.length(), pretenure);
+ if (!maybe_result->ToObject(&result)) return maybe_result;
+ }
+
+ // Copy the characters into the new object.
+ SeqAsciiString* string_result = SeqAsciiString::cast(result);
+ for (int i = 0; i < string.length(); i++) {
+ string_result->SeqAsciiStringSet(i,
bnoordhuis1 2012/12/07 04:54:47 AllocateRawAsciiString and SeqAsciiString don't ex
+ string[i] & String::kMaxAsciiCharCodeU);
+ }
+ return result;
+}
+
+
MaybeObject* Heap::AllocateStringFromUtf8Slow(Vector<const char> string,
int non_ascii_start,
PretenureFlag pretenure) {
« no previous file with comments | « src/heap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698