About redundant Jetpack API's

0 views
Skip to first unread message

download

unread,
Mar 18, 2010, 2:10:36 PM3/18/10
to mozilla-la...@googlegroups.com
Was taking a look at the videos and noticed that the system currently in use for packaging API's is rather redundant.
While this probably won't present a problem for Storage space it may cause problems with RAM usage.
Came up with a system I think might help and thought I'd throw it out there.

Using a global object to hold the API code, with a piece of "bootloader" code in each Jetpack to load it.
The bootloader will cycle through all the API's it has in it's Jetpack and check each one against the global object.
if(JPAPI==undefined) JPAPI={}; //if there is no JPAPI object create it

/*
http://img691.imageshack.us/img691/9828/jpapi.png
JPAPI is an object of the following format:
{
    "098f6bcd4621d373cade4e832627b4f6a94a8fe5ccb19ba61c4c0873d391e987982fbbd3": //hash
    {
        name:"JPCore",
        version:"0.8",
        api:{}, //a reference to the API object
        refcount:1 //a reference counter to know when to unload this API
    }
}

apiList is an array of objects that have the following format:
{
    name:"JPCore",
    version:"0.8",
    hash:"098f6bcd4621d373cade4e832627b4f6a94a8fe5ccb19ba61c4c0873d391e987982fbbd3",
    path:"/path/to/code/file.ext"
}
hash is the concatenated md5 and sha1 hashes of the actual code file.

*/

for(var i=0;i<apiList.length;i++)
{
    var api=apiList[i];
    if(JPAPI[api.hash]==undefined)
    {
        //load code
        JPAPI[api.hash]=
        {
            name:api.name,
            version:api.version,
            api:eval(getFileContents(api.path)),
            refcount:0
        }
    }
    JPAPI[api.hash].refcount++;
    this[api.name]=JPAPI[api.hash].api;
}

//to unload:
for(var i=0;i<apiList.length;i++)
{
    var api=apiList[i];
    delete this[api.name];
    JPAPI[api.hash].refcount--;
    if(JPAPI[api.hash].refcount==0) delete JPAPI[api.hash];
}

Feedback appreciated.
jpapi.png
Reply all
Reply to author
Forward
0 new messages