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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « compiled/bindings/generator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2017 eyeo GmbH 3 * Copyright (C) 2006-2017 eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
397 397
398 // End class definition 398 // End class definition
399 399
400 printf("});\n"); 400 printf("});\n");
401 401
402 // Print static members 402 // Print static members
403 403
404 DifferentiatorInfo differentiator = cls.subclass_differentiator; 404 DifferentiatorInfo differentiator = cls.subclass_differentiator;
405 if (differentiator.offset != SIZE_MAX) 405 if (differentiator.offset != SIZE_MAX)
406 { 406 {
407 printf("var %s_mapping = \n", cls.name.c_str());
408 puts("{");
409 for (const auto& item : differentiator.mapping)
410 printf(" %i: '%s',\n", item.first, item.second.c_str());
411 puts("};");
412
413 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); 407 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str());
414 puts("{"); 408 puts("{");
415 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset); 409 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset);
416 printf(" if (type in %s_mapping)\n", cls.name.c_str()); 410 printf(" if (type in %s_mapping)\n", cls.name.c_str());
417 printf(" return new (exports[%s_mapping[type]])(ptr);\n", cls.name.c_st r()); 411 printf(" return new %s_mapping[type](ptr);\n", cls.name.c_str());
418 printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_s tr()); 412 printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_s tr());
419 puts("};"); 413 puts("};");
420 } 414 }
421 else 415 else
422 { 416 {
423 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str()); 417 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str());
424 puts("{"); 418 puts("{");
425 printf(" return new exports.%s(ptr);\n", cls.name.c_str()); 419 printf(" return new exports.%s(ptr);\n", cls.name.c_str());
426 puts("};"); 420 puts("};");
427 } 421 }
428 422
429 for (const auto& method : cls.methods) 423 for (const auto& method : cls.methods)
430 { 424 {
431 if (!method.call.instance_function) 425 if (!method.call.instance_function)
432 { 426 {
433 printf("exports.%s.%s = %s;\n", cls.name.c_str(), method.name.c_str(), 427 printf("exports.%s.%s = %s;\n", cls.name.c_str(), method.name.c_str(),
434 wrapCall(method.call).c_str()); 428 wrapCall(method.call).c_str());
435 } 429 }
436 } 430 }
437 } 431 }
432
433 void printClassMapping(const ClassInfo& cls)
434 {
435 DifferentiatorInfo differentiator = cls.subclass_differentiator;
436 if (differentiator.offset == SIZE_MAX)
437 return;
438
439 printf("var %s_mapping = \n", cls.name.c_str());
440 puts("{");
441 for (const auto& item : differentiator.mapping)
442 printf(" %i: exports.%s,\n", item.first, item.second.c_str());
443 puts("};");
444 }
438 } 445 }
439 446
440 void printBindings() 447 void printBindings()
441 { 448 {
442 bindings_internal::printHelpers(); 449 bindings_internal::printHelpers();
443 450
444 for (const auto& item : classes) 451 for (const auto& cls : classes)
445 bindings_internal::printClass(item); 452 bindings_internal::printClass(cls);
453 for (const auto& cls : classes)
454 bindings_internal::printClassMapping(cls);
446 } 455 }
OLDNEW
« 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