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

Side by Side Diff: compiled/bindings.ipp

Issue 29398669: Issue 5063 - [emscripten] Make FilterNotifier calls more efficient (Closed) Base URL: https://hg.adblockplus.org/adblockpluscore
Patch Set: Rebased and made the code deal with 64-bit properties Created April 7, 2017, 7:16 a.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.cpp ('k') | compiled/filter/ActiveFilter.h » ('j') | 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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 result += " if (result)\n"; 453 result += " if (result)\n";
454 result += " {\n"; 454 result += " {\n";
455 455
456 auto it = classes.find(call.pointerType); 456 auto it = classes.find(call.pointerType);
457 if (it == classes.end()) 457 if (it == classes.end())
458 throw std::runtime_error("Function " + std::string(call.name) + " return s pointer to unknown class"); 458 throw std::runtime_error("Function " + std::string(call.name) + " return s pointer to unknown class");
459 459
460 const ClassInfo& cls = it->second; 460 const ClassInfo& cls = it->second;
461 auto offset = cls.subclass_differentiator.offset; 461 auto offset = cls.subclass_differentiator.offset;
462 if (offset == SIZE_MAX) 462 if (offset == SIZE_MAX)
463 result += " result = " + cls.name + "(result);\n"; 463 result += " result = exports." + cls.name + "(result);\n";
464 else 464 else
465 { 465 result += " result = exports." + cls.name + ".fromPointer(result);\n" ;
466 result += " var type = HEAP32[result + " + std::to_string(offset)+ " >> 2];\n";
467 result += " if (type in " + cls.name + "_mapping)\n";
468 result += " result = new (exports[" + cls.name + "_mapping[type]])( result);\n";
469 result += " else\n";
470 result += " throw new Error('Unexpected " + cls.name + " type: ' + type);\n";
471 }
472 466
473 result += " }\n"; 467 result += " }\n";
474 result += " else\n"; 468 result += " else\n";
475 result += " result = null;\n"; 469 result += " result = null;\n";
476 return result; 470 return result;
477 } 471 }
478 else 472 else
479 throw std::runtime_error("Unexpected return type for " + std::string(call. name)); 473 throw std::runtime_error("Unexpected return type for " + std::string(call. name));
480 } 474 }
481 475
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 { 578 {
585 Module._ReleaseRef(this._pointer + ref_counted_offset); 579 Module._ReleaseRef(this._pointer + ref_counted_offset);
586 }; 580 };
587 return result; 581 return result;
588 } 582 }
589 )"); 583 )");
590 } 584 }
591 585
592 void printClass(const ClassInfo& cls) 586 void printClass(const ClassInfo& cls)
593 { 587 {
588 printf("exports.%s = createClass(%s, %i);\n", cls.name.c_str(),
589 (cls.baseClass ? ("exports." + cls.baseClass->name).c_str() : "null"),
590 cls.ref_counted_offset);
591
594 DifferentiatorInfo differentiator = cls.subclass_differentiator; 592 DifferentiatorInfo differentiator = cls.subclass_differentiator;
595 if (differentiator.offset != SIZE_MAX) 593 if (differentiator.offset != SIZE_MAX)
596 { 594 {
597 printf("var %s_mapping = \n", cls.name.c_str()); 595 printf("var %s_mapping = \n", cls.name.c_str());
598 puts("{"); 596 puts("{");
599 for (const auto& item : differentiator.mapping) 597 for (const auto& item : differentiator.mapping)
600 printf(" %i: '%s',\n", item.first, item.second.c_str()); 598 printf(" %i: '%s',\n", item.first, item.second.c_str());
601 puts("};"); 599 puts("};");
600
601 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str());
602 puts("{");
603 printf(" var type = HEAP32[ptr + %i >> 2];\n", differentiator.offset);
604 printf(" if (type in %s_mapping)\n", cls.name.c_str());
605 printf(" return new (exports[%s_mapping[type]])(ptr);\n", cls.name.c_st r());
606 printf(" throw new Error('Unexpected %s type: ' + type);\n", cls.name.c_s tr());
607 puts("};");
602 } 608 }
603 609 else
604 printf("exports.%s = createClass(%s, %i);\n", cls.name.c_str(), 610 {
605 (cls.baseClass ? ("exports." + cls.baseClass->name).c_str() : "null"), 611 printf("exports.%s.fromPointer = function(ptr)\n", cls.name.c_str());
606 cls.ref_counted_offset); 612 puts("{");
613 printf(" return new exports.%s(ptr);\n", cls.name.c_str());
614 puts("};");
615 }
607 616
608 for (const auto& item : cls.properties) 617 for (const auto& item : cls.properties)
609 { 618 {
610 printf("Object.defineProperty(exports.%s.prototype, '%s', {%s});\n", 619 printf("Object.defineProperty(exports.%s.prototype, '%s', {%s});\n",
611 cls.name.c_str(), item.name.c_str(), 620 cls.name.c_str(), item.name.c_str(),
612 generatePropertyDescriptor(item).c_str()); 621 generatePropertyDescriptor(item).c_str());
613 } 622 }
614 623
615 for (const auto& item : cls.methods) 624 for (const auto& item : cls.methods)
616 { 625 {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
772 bindings_internal::register_differentiator( 781 bindings_internal::register_differentiator(
773 bindings_internal::TypeInfo<ClassType>(), offset, mapping); 782 bindings_internal::TypeInfo<ClassType>(), offset, mapping);
774 return *this; 783 return *this;
775 } 784 }
776 }; 785 };
777 786
778 void custom_generator(bindings_internal::CustomGenerator generator) 787 void custom_generator(bindings_internal::CustomGenerator generator)
779 { 788 {
780 bindings_internal::customGenerators.push_back(generator); 789 bindings_internal::customGenerators.push_back(generator);
781 } 790 }
OLDNEW
« no previous file with comments | « compiled/bindings.cpp ('k') | compiled/filter/ActiveFilter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld