asSFuncPtr executable size optimization

Started by
2 comments, last by AgentC 11 years, 3 months ago

For my personal use (Urho3D engine) I've done some modifications to AngelScript, some of which are dubious, but here's something that shouldn't be much destructive to performance, but reduce the executable size, possibly even by a hundred KB or so, if there's a lot of classes & functions being registered.

It has to do with the template functions for initializing asSFuncPtr's. While the original template code memclear's the function pointer object (which is possibly also inlined), and then sets the flag member variable according to whether it's a function or method


// Specialization for functions using the generic calling convention
template<>
inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
{
    asSFuncPtr p;
    asMemClear(&p, sizeof(p));
    p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);

    // Mark this as a generic function
    p.flag = 1;

    return p;
}

I've created a non-inline constructor for asSFuncPtr, which does the memclear and sets the flag


asSFuncPtr::asSFuncPtr(asBYTE f)
{
    asMemClear(this, sizeof(asSFuncPtr));
    flag = f;
}

By using that, the template functions become shortened and should consume less memory:


// Specialization for functions using the generic calling convention
template<>
inline asSFuncPtr asFunctionPtr<asGENFUNC_t>(asGENFUNC_t func)
{
    asSFuncPtr p(1);
    p.ptr.f.func = reinterpret_cast<asFUNCTION_t>(func);

    return p;
}

Advertisement

Thanks. I'll incorporate this change.

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 checked in the changes in revision 1527.

In my regression test suite this change reduced the size of the executable with 57KB.

Regards,

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

Nice to hear!

This topic is closed to new replies.

Advertisement