Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: compiled/bindings/generator.cpp

Issue 29433621: Noissue - [emscripten] Make bindings slightly more efficient by resolving classes when mappings are… (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Created May 8, 2017, 1:25 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « compiled/bindings/generator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: compiled/bindings/generator.cpp
===================================================================
--- a/compiled/bindings/generator.cpp
+++ b/compiled/bindings/generator.cpp
@@ -399,27 +399,21 @@ namespace bindings_internal
printf("});\n");
// Print static members
DifferentiatorInfo differentiator = cls.subclass_differentiator;
if (differentiator.offset != SIZE_MAX)
{
- printf("var %s_mapping = \n", cls.name.c_str());
- puts("{");
- for (const auto& item : differentiator.mapping)
- printf(" %i: '%s',\n", item.first, item.second.c_str());
- puts("};");
-
printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str());
puts("{");
printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset);
printf(" if (type in %s_mapping)\n", cls.name.c_str());
- printf(" return new (exports[%s_mapping[type]])(ptr);\n", cls.name.c_str());
+ printf(" return new %s_mapping[type](ptr);\n", cls.name.c_str());
printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_str());
puts("};");
}
else
{
printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str());
puts("{");
printf(" return new exports.%s(ptr);\n", cls.name.c_str());
@@ -430,17 +424,32 @@ namespace bindings_internal
{
if (!method.call.instance_function)
{
printf("exports.%s.%s = %s;\n", cls.name.c_str(), method.name.c_str(),
wrapCall(method.call).c_str());
}
}
}
+
+ void printClassMapping(const ClassInfo& cls)
+ {
+ DifferentiatorInfo differentiator = cls.subclass_differentiator;
+ if (differentiator.offset == SIZE_MAX)
+ return;
+
+ printf("var %s_mapping = \n", cls.name.c_str());
+ puts("{");
+ for (const auto& item : differentiator.mapping)
+ printf(" %i: exports.%s,\n", item.first, item.second.c_str());
+ puts("};");
+ }
}
void printBindings()
{
bindings_internal::printHelpers();
- for (const auto& item : classes)
- bindings_internal::printClass(item);
+ for (const auto& cls : classes)
+ bindings_internal::printClass(cls);
+ for (const auto& cls : classes)
+ bindings_internal::printClassMapping(cls);
}
« no previous file with comments | « compiled/bindings/generator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld