[Pkg-javascript-commits] [ltx] 186/469: element: replace forEach with for loops (optimization)

Jonas Smedegaard dr at jones.dk
Wed Aug 31 13:01:50 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository ltx.

commit f322d4cc9735cbe9fe5288245f55d24f1ead51e8
Author: Astro <astro at spaceboyz.net>
Date:   Fri Dec 9 21:27:21 2011 +0100

    element: replace forEach with for loops (optimization)
    
    thx dodo
---
 lib/element.js | 49 ++++++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/lib/element.js b/lib/element.js
index d14f016..075fe06 100644
--- a/lib/element.js
+++ b/lib/element.js
@@ -72,32 +72,34 @@ Element.prototype.getChild = function(name, xmlns) {
  **/
 Element.prototype.getChildren = function(name, xmlns) {
     var result = [];
-    this.children.forEach(function(child) {
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
         if (child.getName &&
             child.getName() == name &&
             (!xmlns || child.getNS() == xmlns))
             result.push(child);
-    });
+    }
     return result;
 };
 
 Element.prototype.getText = function() {
     var text = "";
-    this.children.forEach(function(child) {
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
         if (typeof child == 'string')
             text += child;
-    });
+    }
     return text;
 };
 
 Element.prototype.getChildText = function(name) {
     var text = null;
-    this.children.forEach(function(el) {
-        if (!text && el.name == name)
-        {
-            text = el.getText();
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
+        if (!text && child.name == name) {
+            text = child.getText();
         }
-    });
+    }
     return text;
 };
 
@@ -175,9 +177,10 @@ Element.prototype.clone = function() {
 	if (this.attrs.hasOwnProperty(k))
 	    clone.attrs[k] = this.attrs[k];
     }
-    this.children.forEach(function(child) {
+    for(var i = 0; i < this.children.length; i++) {
+	var child = this.children[i];
 	clone.cnode(child.clone ? child.clone() : child);
-    });
+    }
     return clone;
 };
 
@@ -210,18 +213,18 @@ Element.prototype.write = function(writer) {
         writer("/>");
     } else {
         writer(">");
-        this.children.forEach(function(child) {
-	    if (!child)
-		/* Skip null/undefined */
-		return;
-
-            if (child.write)
-                child.write(writer);
-            else if (typeof child === 'string')
-                writer(escapeXmlText(child));
-	    else if (child.toString)
-                writer(escapeXmlText(child.toString()));
-        });
+	for(var i = 0; i < this.children.length; i++) {
+	    var child = this.children[i];
+	    /* Skip null/undefined */
+	    if (child) {
+		if (child.write)
+		    child.write(writer);
+		else if (typeof child === 'string')
+			writer(escapeXmlText(child));
+		else if (child.toString)
+			writer(escapeXmlText(child.toString()));
+	    }
+        }
         writer("</");
         writer(this.name);
         writer(">");

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git



More information about the Pkg-javascript-commits mailing list