Chromium Code Reviews| Index: sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| index 2f81f2d981126de5a93d3f680db7a081043b5261..11136c0cf31f8625753550df2f10f5eb98ffc932 100644 |
| --- a/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| +++ b/sdk/lib/_internal/compiler/implementation/js_emitter/code_emitter_task.dart |
| @@ -974,13 +974,29 @@ class CodeEmitterTask extends CompilerTask { |
| jsAst.Expression generateDispatchPropertyInitialization() { |
| return js('!#', js.fun([], [ |
| - js('var objectProto = Object.prototype'), |
| + |
| + // On V8, the 'intern' function converts a string to a symbol, which |
| + // makes property access much faster. |
| + new jsAst.FunctionDeclaration(new jsAst.VariableDeclaration('intern'), |
| + js.fun(['s'], [ |
| + js('var o = {}'), |
| + js('o[s] = 1'), |
| + js.return_(js('Object.keys(convertToFastObject(o))[0]'))])), |
| + |
| + // To ensure that different programs loaded into the same context (page) |
| + // use distinct dispatch properies, we place an object on `Object` to |
| + // contain the names already in use. |
| + js('var tableProperty = "___dart_dispatch_property_names_"'), |
| + js('var usedProperties = Object[tableProperty] ||' |
| + '(Object[tableProperty] = Object.create(null))'), |
|
floitsch
2014/02/12 15:33:39
We could also just store the counter of the last u
sra1
2014/02/12 22:01:20
Not if every program has an MD5-like root property
|
| + |
| + js('var rootProperty = "${generateDispatchPropertyName(0)}"'), |
| js.for_('var i = 0', null, 'i++', [ |
| - js('var property = "${generateDispatchPropertyName(0)}"'), |
| - js.if_('i > 0', js('property = rootProperty + "_" + i')), |
| - js.if_('!(property in objectProto)', |
| - js.return_( |
| - js('init.dispatchPropertyName = property')))])])()); |
| + js('property = intern(rootProperty + "_" + i + "_")'), |
|
floitsch
2014/02/12 10:38:25
Isn't generateDispatchPropertyName supposed to do
sra1
2014/02/12 22:01:20
The seed was for when I was generating a list of n
|
| + js.if_('!(property in usedProperties)', [ |
| + js('usedProperties[property] = 1'), |
|
floitsch
2014/02/12 10:38:25
That line seems to be important :)
|
| + js.return_( |
| + js('init.dispatchPropertyName = property'))])])])()); |
| } |
| String generateDispatchPropertyName(int seed) { |