diff options
author | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-09 03:39:13 +0000 |
---|---|---|
committer | jsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68> | 2011-01-09 03:39:13 +0000 |
commit | bf8b58267edaca28b2306da5300431e5a049896f (patch) | |
tree | 1b71c85f52715dc15369388174fd82f97a39b08f /sca-cpp/trunk/modules/js/htdocs | |
parent | 2e9c610931b4e0a6bab25b1fe5dbd0def45ee126 (diff) |
Add a composite similar to the travel tutorial app to the sample dashboard. Minor Javascript performance improvements to speed up the layout of big composites.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1056881 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/elemutil.js | 14 | ||||
-rw-r--r-- | sca-cpp/trunk/modules/js/htdocs/util.js | 27 |
2 files changed, 25 insertions, 16 deletions
diff --git a/sca-cpp/trunk/modules/js/htdocs/elemutil.js b/sca-cpp/trunk/modules/js/htdocs/elemutil.js index 00baab06c8..be976c3982 100644 --- a/sca-cpp/trunk/modules/js/htdocs/elemutil.js +++ b/sca-cpp/trunk/modules/js/htdocs/elemutil.js @@ -206,17 +206,21 @@ function selector(s) { * Return the value of the attribute with the given name. */ function namedAttributeValue(name, l) { - var f = filter(function(v) { return isAttribute(v) && attributeName(v) == name; }, l); - if (isNil(f)) - return null; - return caddr(car(f)); + return memo(l, name, function() { + var f = filter(function(v) { return isAttribute(v) && attributeName(v) == name; }, l); + if (isNil(f)) + return null; + return caddr(car(f)); + }); } /** * Return child elements with the given name. */ function namedElementChildren(name, l) { - return filter(function(v) { return isElement(v) && elementName(v) == name; }, l); + return memo(l, name, function() { + return filter(function(v) { return isElement(v) && elementName(v) == name; }, l); + }); } /** diff --git a/sca-cpp/trunk/modules/js/htdocs/util.js b/sca-cpp/trunk/modules/js/htdocs/util.js index 0f966b180e..b90c96db2d 100644 --- a/sca-cpp/trunk/modules/js/htdocs/util.js +++ b/sca-cpp/trunk/modules/js/htdocs/util.js @@ -65,14 +65,8 @@ function reverse(l) { } function isNil(v) { - if (v == null) + if (v == null || typeof v == 'undefined' || (v.constructor == Array && v.length == 0)) return true; - if ('' + v == 'undefined') - return true; - try { - if (isList(v) && v.length == 0) - return true; - } catch (e) {} return false; } @@ -89,10 +83,8 @@ function isString(v) { } function isList(v) { - try { - if (v.constructor == Array) - return true; - } catch (e) {} + if (v != null && typeof v != 'undefined' && v.constructor == Array) + return true; return false; } @@ -102,7 +94,11 @@ function isTaggedList(v, t) { return false; } +var emptylist = new Array(); + function mklist() { + if (arguments.length == 0) + return emptylist; var a = new Array(); for (i = 0; i < arguments.length; i++) a[i] = arguments[i]; @@ -206,3 +202,12 @@ function writeValue(v) { return '(' + writeValue(car(v)) + writeList(cdr(v)) + ')'; } +/** + * Apply a function and memoize its result. + */ +function memo(obj, key, f) { + if (obj[key]) + return obj[key]; + return obj[key] = f(); +} + |