Chromium Code Reviews| Index: pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart |
| diff --git a/pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart b/pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart |
| index c5142233d4954413f27a4c14681d9ff2b98edd74..22b4bcffd64a71af904b6bfd5511478a12e1e63e 100644 |
| --- a/pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart |
| +++ b/pkg/compiler/lib/src/js_emitter/old_emitter/nsm_emitter.dart |
| @@ -122,29 +122,39 @@ class NsmEmitter extends CodeEmitterHelper { |
| List<jsAst.Statement> statements = <jsAst.Statement>[]; |
| if (trivialNsmHandlers.length == 0) return statements; |
| + bool minify = compiler.enableMinification; |
| + bool useDiffEncoding = minify && trivialNsmHandlers.length > 30; |
| + |
| // Find out how many selectors there are with the special calling |
| // convention. |
| - bool hasSpecialCallingConvention(Selector selector) { |
| - return backend.isInterceptedName(selector.name); |
| - } |
| Iterable<Selector> specialSelectors = trivialNsmHandlers.where( |
| - (Selector s) => backend.isInterceptedName(s.name)); |
| + (Selector s) => backend.isInterceptedName(s.name)); |
| Iterable<Selector> ordinarySelectors = trivialNsmHandlers.where( |
| - (Selector s) => !backend.isInterceptedName(s.name)); |
| + (Selector s) => !backend.isInterceptedName(s.name)); |
| // Get the short names (JS names, perhaps minified). |
| Iterable<jsAst.Name> specialShorts = |
| - specialSelectors.map(namer.invocationMirrorInternalName); |
| + specialSelectors.map(namer.invocationMirrorInternalName); |
|
sigurdm
2015/06/25 09:15:00
Indent
herhut
2015/06/25 09:21:24
Done.
|
| Iterable<jsAst.Name> ordinaryShorts = |
| - ordinarySelectors.map(namer.invocationMirrorInternalName); |
| - |
| - bool minify = compiler.enableMinification; |
| - bool useDiffEncoding = minify && trivialNsmHandlers.length > 30; |
| - |
| - jsAst.Expression diffEncoding = new _DiffEncodedListOfNames( |
| - [specialShorts, ordinaryShorts], |
| - useDiffEncoding); |
| + ordinarySelectors.map(namer.invocationMirrorInternalName); |
| + jsAst.Expression sortedShorts; |
| + Iterable<String> sortedLongs; |
| + if (useDiffEncoding) { |
| + sortedShorts = new _DiffEncodedListOfNames( |
| + [specialShorts, ordinaryShorts]); |
| + } else { |
| + Iterable<Selector> sorted = |
| + [specialSelectors, ordinarySelectors].expand((e) => (e)); |
|
sigurdm
2015/06/25 09:15:00
Maybe call the special selectors intercepted selec
herhut
2015/06/25 09:21:24
Done.
|
| + sortedShorts = js.concatenateStrings( |
| + js.joinLiterals( |
| + sorted.map(namer.invocationMirrorInternalName), |
| + js.stringPart(",")), |
| + addQuotes: true); |
| + |
| + sortedLongs = sorted.map((selector) => |
| + selector.invocationMirrorMemberName); |
| + } |
| // Startup code that loops over the method names and puts handlers on the |
| // Object class to catch noSuchMethod invocations. |
| ClassElement objectClass = compiler.objectClass; |
| @@ -192,19 +202,17 @@ class NsmEmitter extends CodeEmitterHelper { |
| } |
| } |
| }''', {'objectClass': js.quoteName(namer.className(objectClass)), |
| - 'diffEncoding': diffEncoding})); |
| + 'diffEncoding': sortedShorts})); |
| } else { |
| // No useDiffEncoding version. |
| - Iterable<String> longs = trivialNsmHandlers.map((selector) => |
| - selector.invocationMirrorMemberName); |
| statements.add(js.statement( |
| 'var objectClassObject = processedClasses.collected[#objectClass],' |
| ' shortNames = #diffEncoding.split(",")', |
| {'objectClass': js.quoteName(namer.className(objectClass)), |
| - 'diffEncoding': diffEncoding})); |
| + 'diffEncoding': sortedShorts})); |
| if (!minify) { |
| statements.add(js.statement('var longNames = #longs.split(",")', |
| - {'longs': js.string(longs.join(','))})); |
| + {'longs': js.string(sortedLongs.join(','))})); |
| } |
| statements.add(js.statement( |
| 'if (objectClassObject instanceof Array)' |
| @@ -283,10 +291,8 @@ class _DiffEncodedListOfNames extends jsAst.DeferredString |
| implements AstContainer { |
| String _cachedValue; |
| jsAst.ArrayInitializer ast; |
| - bool useDiffEncoding; |
| - _DiffEncodedListOfNames(Iterable<Iterable<jsAst.Name>> names, |
| - this.useDiffEncoding) { |
| + _DiffEncodedListOfNames(Iterable<Iterable<jsAst.Name>> names) { |
| // Store the names in ArrayInitializer nodes to make them discoverable |
| // by traversals of the ast. |
| ast = new jsAst.ArrayInitializer( |
| @@ -341,15 +347,14 @@ class _DiffEncodedListOfNames extends jsAst.DeferredString |
| int previous = 0; |
| for (String short in shorts) { |
| - if (useDiffEncoding && |
| - short.length <= NsmEmitter.MAX_MINIFIED_LENGTH_FOR_DIFF_ENCODING) { |
| + if (short.length <= NsmEmitter.MAX_MINIFIED_LENGTH_FOR_DIFF_ENCODING) { |
| int base63 = fromBase88(short); |
| int diff = base63 - previous; |
| previous = base63; |
| String base26Diff = toBase26(diff); |
| diffEncoding.write(base26Diff); |
| } else { |
| - if (useDiffEncoding || diffEncoding.length != 0) { |
| + if (diffEncoding.length != 0) { |
| diffEncoding.write(','); |
| } |
| diffEncoding.write(short); |
| @@ -361,15 +366,10 @@ class _DiffEncodedListOfNames extends jsAst.DeferredString |
| StringBuffer buffer = new StringBuffer(); |
| for (jsAst.ArrayInitializer list in ast.elements) { |
| if (buffer.isNotEmpty) { |
| - if (useDiffEncoding) { |
| - // Emit period that resets the diff base to zero when we switch to |
| - // normal calling convention (this avoids the need to code negative |
| - // diffs). |
| - buffer.write("."); |
| - } else { |
| - // Write a separator for the next sequence. |
| - buffer.write(","); |
| - } |
| + // Emit period that resets the diff base to zero when we switch to |
| + // normal calling convention (this avoids the need to code negative |
| + // diffs). |
| + buffer.write("."); |
| } |
| List<jsAst.Name> names = list.elements; |
| _computeDiffEncodingForList(names, buffer); |