changeset 19857:14fddba036f8

hgweb: optimize process_dates function This function looped over every node due to getElementsByTagName('*'), instead of using selectors. In this patch we use querySelectorAll('.age') and process only these nodes, which is much faster and also doesn't require extra condition. Browser compatibility isn't sacrificed: IE 8+, FF 3.5+, Opera 10+.
author Alexander Plavin <alexander@plav.in>
date Fri, 06 Sep 2013 13:30:58 +0400
parents 28b1b7b9b4a9
children 4a8c5a51f7a1
files mercurial/templates/static/mercurial.js
diffstat 1 files changed, 8 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templates/static/mercurial.js	Thu Aug 29 09:22:15 2013 -0700
+++ b/mercurial/templates/static/mercurial.js	Fri Sep 06 13:30:58 2013 +0400
@@ -253,21 +253,18 @@
 		}
 	}
 
-	var nodes = document.getElementsByTagName('*');
-	var ageclass = new RegExp('\\bage\\b');
+	var nodes = document.querySelectorAll('.age');
 	var dateclass = new RegExp('\\bdate\\b');
 	for (var i=0; i<nodes.length; ++i){
 		var node = nodes[i];
 		var classes = node.className;
-		if (ageclass.test(classes)){
-			var agevalue = age(node.textContent);
-			if (dateclass.test(classes)){
-				// We want both: date + (age)
-				node.textContent += ' ('+agevalue+')';
-			} else {
-				node.title = node.textContent;
-				node.textContent = agevalue;
-			}
+		var agevalue = age(node.textContent);
+		if (dateclass.test(classes)){
+			// We want both: date + (age)
+			node.textContent += ' ('+agevalue+')';
+		} else {
+			node.title = node.textContent;
+			node.textContent = agevalue;
 		}
 	}
 }