From patchwork Thu Aug 8 13:16:57 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,2] hgweb: optimize process_dates function From: Alexander Plavin X-Patchwork-Id: 2096 Message-Id: <2e3064b1a8b3719bc896.1375967817@debian-alexander.dolgopa> To: mercurial-devel@selenic.com Date: Thu, 08 Aug 2013 17:16:57 +0400 # HG changeset patch # User Alexander Plavin # Date 1374682432 -14400 # Wed Jul 24 20:13:52 2013 +0400 # Node ID 2e3064b1a8b3719bc896e61a5804fd515a0bc9cb # Parent d2e91a2d576deff3bb97fefc1fe71c2a64d64bb6 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+. diff -r d2e91a2d576d -r 2e3064b1a8b3 mercurial/templates/static/mercurial.js --- a/mercurial/templates/static/mercurial.js Wed Jul 24 18:53:55 2013 +0400 +++ b/mercurial/templates/static/mercurial.js Wed Jul 24 20:13:52 2013 +0400 @@ -245,21 +245,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