This project is read-only.
1
Vote

Optimize Seadragon._Debug

description

Currently every call to Seadragon.Debug.log (or info, fail, error etc) actually perform a check to see if console is available. It would save a lot of cycles to instead check for the console before defining Seadragon._Debug and in the case when console is not defined, instead define log, debug, etc to be null functions

eg in Seadragon.Debug.pre.js:

if (typeof(console) !== 'undefined' && console != null) {
// Basic logging to Firebug and IE Dev consoles
Seadragon._Debug.prototype = {
    log: function (message, object) {
        ///<summary>Log a message at INFO level</summary>
        if (object) {
            console.log("%s: %o", message, object);
        } else {
            console.log("%s", message);
        }
    },

    info: function (message, object) {
        ///<summary>Log a message at ERROR level</summary>
        this.log(message, object);
    },

    fail: function (message, object) {
        ///<summary>Log a message at FAIL level (e.g. Tile failed to load)</summary>
        this.log(message, object);
    },

    error: function (message, object) {
        ///<summary>Log a message at ERROR level.</summary>
        this.log(message, object);
    }
};
}else{
Seadragon._Debug.prototype = {
    log: function(){},
    info: function(){},
    fail: function(){},
    error: function(){}
};
}

This only has the side effect of requiring firebug to be open when the page is loaded if you want messages, but its a good trade off and will shave off a lot of unnecessary function calls and boolean checks.

Thatcher

comments