Permalink
Browse files

Got rid of redundant cloneJSON implementation.

  • Loading branch information...
1 parent 4131dc3 commit e815675335db8d688074cafbac1d5e494adcb9c8 @mikesamuel committed May 31, 2011
Showing with 13 additions and 19 deletions.
  1. +3 −3 build/jquery-templates-contextesc-compiled.js
  2. +10 −16 src/contextesc/contextesc.js

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -45,7 +45,7 @@ function autoescape( jqueryTemplatesByName ) {
} else if ( hop.call( parsedTemplates, name ) ) {
// Clone one in the given context if none is found.
var base = parsedTemplates[ name ];
- var clone = cloneJson( base );
+ var clone = cloneParseTree( base );
clone.jqueryTemplateName = qname;
assignIds( clone );
return parsedTemplates[ qname ] = clone;
@@ -456,22 +456,16 @@ function autoescape( jqueryTemplatesByName ) {
return parsedTemplates;
}
-// Clones a JSON value.
-var cloneJson;
-if ( typeof JSON !== "undefined" ) {
- cloneJson = function ( ptree ) {
- return JSON.parse( JSON.stringify( ptree ) );
- };
-} else {
- cloneJson = function ( ptree ) {
- var clone = ptree.slice();
- for ( var i = clone.length; --i >= 0; ) {
- if ( typeof clone[ i ] === "object" ) {
- clone[ i ] = cloneJson( clone[ i ] );
- }
+function cloneParseTree( ptree ) {
+ // Once JSON is supported on all interpreters, this can be replaced with
+ // return JSON.parse(JSON.stringify(ptree));
+ var clone = ptree.slice();
+ for ( var i = clone.length; --i >= 0; ) {
+ if ( clone[ i ].push ) { // Recurse if it is an array.
+ clone[ i ] = cloneParseTree( clone[ i ] );
}
- return clone;
- };
+ }
+ return clone;
}
if ( !JQUERY_TMPL_PRECOMPILED ) {

0 comments on commit e815675

Please sign in to comment.