Commit d35c815e authored by whesse@chromium.org's avatar whesse@chromium.org

Move some arrays into functions so they don't get cloned on each new context.

Review URL: http://codereview.chromium.org/164396

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2672 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0b60fe88
......@@ -28,30 +28,89 @@
// -------------------------------------------------------------------
const kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true};
const kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true,
h: true, f: true, l: true, m: true, n: true, r: true, s: true, x: true,
y: true};
// Lazily initialized.
var kVowelSounds = 0;
var kCapitalVowelSounds = 0;
function GetInstanceName(cons) {
if (cons.length == 0) {
return "";
}
var first = %StringToLowerCase(StringCharAt.call(cons, 0));
var mapping = kVowelSounds;
if (kVowelSounds === 0) {
kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true};
kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, h: true,
f: true, l: true, m: true, n: true, r: true, s: true, x: true, y: true};
}
var vowel_mapping = kVowelSounds;
if (cons.length > 1 && (StringCharAt.call(cons, 0) != first)) {
// First char is upper case
var second = %StringToLowerCase(StringCharAt.call(cons, 1));
// Second char is upper case
if (StringCharAt.call(cons, 1) != second)
mapping = kCapitalVowelSounds;
if (StringCharAt.call(cons, 1) != second) {
vowel_mapping = kCapitalVowelSounds;
}
var s = mapping[first] ? "an " : "a ";
}
var s = vowel_mapping[first] ? "an " : "a ";
return s + cons;
}
const kMessages = {
var kMessages = 0;
function FormatString(format, args) {
var result = format;
for (var i = 0; i < args.length; i++) {
var str;
try { str = ToDetailString(args[i]); }
catch (e) { str = "#<error>"; }
result = ArrayJoin.call(StringSplit.call(result, "%" + i), str);
}
return result;
}
function ToDetailString(obj) {
if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toString) {
var constructor = obj.constructor;
if (!constructor) return ToString(obj);
var constructorName = constructor.name;
if (!constructorName) return ToString(obj);
return "#<" + GetInstanceName(constructorName) + ">";
} else {
return ToString(obj);
}
}
function MakeGenericError(constructor, type, args) {
if (IS_UNDEFINED(args)) {
args = [];
}
var e = new constructor(kAddMessageAccessorsMarker);
e.type = type;
e.arguments = args;
return e;
}
/**
* Setup the Script function and constructor.
*/
%FunctionSetInstanceClassName(Script, 'Script');
%SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM);
%SetCode(Script, function(x) {
// Script objects can only be created by the VM.
throw new $Error("Not supported");
});
// Helper functions; called from the runtime system.
function FormatMessage(message) {
if (kMessages === 0) {
kMessages = {
// Error
cyclic_proto: "Cyclic __proto__ value",
// TypeError
......@@ -109,58 +168,8 @@ const kMessages = {
result_not_primitive: "Result of %0 must be a primitive, was %1",
invalid_json: "String '%0' is not valid JSON",
circular_structure: "Converting circular structure to JSON"
};
function FormatString(format, args) {
var result = format;
for (var i = 0; i < args.length; i++) {
var str;
try { str = ToDetailString(args[i]); }
catch (e) { str = "#<error>"; }
result = ArrayJoin.call(StringSplit.call(result, "%" + i), str);
}
return result;
}
function ToDetailString(obj) {
if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toString) {
var constructor = obj.constructor;
if (!constructor) return ToString(obj);
var constructorName = constructor.name;
if (!constructorName) return ToString(obj);
return "#<" + GetInstanceName(constructorName) + ">";
} else {
return ToString(obj);
}
}
function MakeGenericError(constructor, type, args) {
if (IS_UNDEFINED(args)) {
args = [];
};
}
var e = new constructor(kAddMessageAccessorsMarker);
e.type = type;
e.arguments = args;
return e;
}
/**
* Setup the Script function and constructor.
*/
%FunctionSetInstanceClassName(Script, 'Script');
%SetProperty(Script.prototype, 'constructor', Script, DONT_ENUM);
%SetCode(Script, function(x) {
// Script objects can only be created by the VM.
throw new $Error("Not supported");
});
// Helper functions; called from the runtime system.
function FormatMessage(message) {
var format = kMessages[message.type];
if (!format) return "<unknown message " + message.type + ">";
return FormatString(format, message.args);
......
......@@ -39,6 +39,10 @@ function URIAddEncodedOctetToBuffer(octet, result, index) {
function URIEncodeOctets(octets, result, index) {
if (hexCharCodeArray === 0) {
hexCharCodeArray = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
65, 66, 67, 68, 69, 70];
}
index = URIAddEncodedOctetToBuffer(octets[0], result, index);
if (octets[1]) index = URIAddEncodedOctetToBuffer(octets[1], result, index);
if (octets[2]) index = URIAddEncodedOctetToBuffer(octets[2], result, index);
......@@ -316,11 +320,9 @@ function URIEncodeComponent(component) {
}
const hexCharArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F"];
const hexCharCodeArray = [48, 49, 50, 51, 52, 53, 54, 55, 56, 57,
65, 66, 67, 68, 69, 70];
// Lazily initialized.
var hexCharArray = 0;
var hexCharCodeArray = 0;
function HexValueOf(c) {
......@@ -341,6 +343,10 @@ function HexValueOf(c) {
// 64 -> 0040, 62234 -> F31A.
function CharCodeToHex4Str(cc) {
var r = "";
if (hexCharArray === 0) {
hexCharArray = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F"];
}
for (var i = 0; i < 4; ++i) {
var c = hexCharArray[cc & 0x0F];
r = c + r;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment