Skip to content

Commit

Permalink
performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
afri committed Sep 9, 2013
1 parent e265a5d commit 1b245c3
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 18 deletions.
2 changes: 2 additions & 0 deletions modules/array.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ exports.isArrayLike = isArrayLike;
@return {Boolean} `true` if the element was removed, `false` if `elem` is not in `arr`.
@summary Removes the first element in the array equal (under `===`) to `elem`.
*/
__js {
function remove(arr, elem) {
var idx = arr.indexOf(elem);
if (idx == -1) return false;
arr.splice(idx, 1);
return true;
}
exports.remove = remove;
}

/**
@function contains
Expand Down
25 changes: 15 additions & 10 deletions src/sys/apollo-sys-common.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ __js exports.isQuasi = function(obj) {
@summary Create a Quasi
@summary See [../../modules/quasi::Quasi]
*/
exports.Quasi = function(arr) { return __oni_rt.Quasi.apply(__oni_rt, arr)};
__js exports.Quasi = function(arr) { return __oni_rt.Quasi.apply(__oni_rt, arr)};


/**
Expand Down Expand Up @@ -469,7 +469,7 @@ var pendingLoads = {};
function makeRequire(parent) {
// make properties of this require function accessible in requireInner:
var rf = function(module, settings) {
var opts = exports.extendObject({}, settings);
__js var opts = exports.extendObject({}, settings);
if (opts.callback) {
(spawn (function() {
try {
Expand All @@ -485,6 +485,8 @@ function makeRequire(parent) {
return requireInner(module, rf, parent, opts);
};

__js {

rf.resolve = function(module, settings) {
var opts = exports.extendObject({}, settings);
return resolve(module, rf, parent, opts);
Expand All @@ -511,11 +513,14 @@ function makeRequire(parent) {
// module compiler functions indexed by extension:
rf.extensions = getExtensions_hostenv();
}

} // __js

return rf;
}
exports._makeRequire = makeRequire;

function augmentHubs(hubs) {
__js function augmentHubs(hubs) {
// add additional methods to the `require.hubs` array:
hubs.addDefault = function(hub) {
if (!this.defined(hub[0])) {
Expand Down Expand Up @@ -549,7 +554,7 @@ function html_sjs_extractor(html, descriptor) {
}

// helper to resolve aliases
function resolveAliases(module, aliases) {
__js function resolveAliases(module, aliases) {
var ALIAS_REST = /^([^:]+):(.*)$/;
var alias_rest, alias;
var rv = module;
Expand All @@ -564,7 +569,7 @@ function resolveAliases(module, aliases) {
}

// helper to resolve hubs
function resolveHubs(module, hubs, require_obj, parent, opts) {
__js function resolveHubs(module, hubs, require_obj, parent, opts) {
var path = module;
var loader = opts.loader || default_loader;
var src = opts.src || default_src_loader;
Expand Down Expand Up @@ -601,7 +606,7 @@ function resolveHubs(module, hubs, require_obj, parent, opts) {
}

// default module loader
function default_src_loader(path) {
__js function default_src_loader(path) {
throw new Error("Don't know how to load module at "+path);
}

Expand Down Expand Up @@ -760,7 +765,7 @@ function github_src_loader(path) {
}

// resolve module id to {path,loader,src}
function resolve(module, require_obj, parent, opts) {
__js function resolve(module, require_obj, parent, opts) {
// apply local aliases:
var path = resolveAliases(module, require_obj.alias);

Expand Down Expand Up @@ -797,7 +802,7 @@ function resolve(module, require_obj, parent, opts) {
@function resolve
@summary Apollo's internal URL resolver
*/
exports.resolve = function(url, require_obj, parent, opts) {
__js exports.resolve = function(url, require_obj, parent, opts) {
require_obj = require_obj || exports.require;
parent = parent || getTopReqParent_hostenv();
opts = opts || {};
Expand All @@ -819,9 +824,9 @@ function requireInner(module, require_obj, parent, opts) {
}

// top-level require function:
exports.require = makeRequire(getTopReqParent_hostenv());
__js exports.require = makeRequire(getTopReqParent_hostenv());

exports.require.modules['builtin:apollo-sys.sjs'] = {
__js exports.require.modules['builtin:apollo-sys.sjs'] = {
id: 'builtin:apollo-sys.sjs',
exports: exports,
loaded_from: "[builtin]",
Expand Down
8 changes: 4 additions & 4 deletions src/sys/apollo-sys-xbrowser.sjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@


var location;
function determineLocation() {
__js function determineLocation() {
if (!location) {
location = {};
var scripts = document.getElementsByTagName("script"), matches;
Expand Down Expand Up @@ -229,7 +229,7 @@ function getXDomainCaps_hostenv() {
@function getTopReqParent_hostenv
@summary Return top-level require parent (for converting relative urls in absolute ones)
*/
function getTopReqParent_hostenv() {
__js function getTopReqParent_hostenv() {
var base = determineLocation().req_base;
return { id: base,
loaded_from: base,
Expand All @@ -245,7 +245,7 @@ function getTopReqParent_hostenv() {
@param {Object} [parent] Module parent (possibly undefined if loading from top-level)
@return {String} Absolute URL
*/
function resolveSchemelessURL_hostenv(url_string, req_obj, parent) {
__js function resolveSchemelessURL_hostenv(url_string, req_obj, parent) {
if (req_obj.path && req_obj.path.length)
url_string = exports.constructURL(req_obj.path, url_string);
return exports.canonicalizeURL(url_string, parent.id);
Expand Down Expand Up @@ -390,7 +390,7 @@ function request_hostenv(url, settings) {
//----------------------------------------------------------------------
// initial list of hubs and extensions:

function getHubs_hostenv() {
__js function getHubs_hostenv() {
return [
["sjs:", determineLocation().location ?
determineLocation().location :
Expand Down
4 changes: 2 additions & 2 deletions stratified-aot.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stratified-node.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion stratified.js

Large diffs are not rendered by default.

0 comments on commit 1b245c3

Please sign in to comment.