[PATCH] Use vftable for interface methods.

Started by
1 comment, last by WitchLord 10 years, 4 months ago

A short one this time ;)

This appends chunks to the end of script object types' virtual function tables corresponding to the methods of the interfaces it implements, and records the offset of each of its interfaces into its table. That is, it stores a virtual function at the index of (interface offset + index of method in interface). I co-opted the vfTableIdx member for asFUNC_INTERFACE functions to indicate the local index of the method in the interface to easily access that.

This turns a CALLINTF on an interface function from a full O(n) search on all methods in the class to a short linear search on the interfaces implemented by the class, and then a lookup into the virtual function table. It would be possible to use a map for the interface offsets to lower the complexity of that particular search, but because the amount of interfaces implemented by a class is usually low, the added complication of the map logic is probably not worth it.

We do not use bytecode saving, so the as_restore bits have not gone through real-world testing, but the angelscript tests pass using it and it isn't terribly complex.

Advertisement

Thanks a lot for the patch. I'll see if I can have it included with 2.28.1.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I've added this improvement in revision 1795.

Thanks,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

This topic is closed to new replies.

Advertisement