git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/3] gitweb.js: No need for loop in blame_incremental's handleResponse()

From
Jakub Narebski <jnareb@gmail.com>
Date
May 27, 2011, 13:50 UTC
Message-ID
<1306504201-18014-3-git-send-email-jnareb@gmail.com>
In-Reply-To
<1306504201-18014-1-git-send-email-jnareb@gmail.com>

JavaScript is single-threaded, so there is no need for protecting against changes to XMLHttpRequest object behind event handler back.

Therefore there is no need for loop that was here in case `xhr' got new changes while processing current changes. This should make code a bit more clear.

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Remove and simplify code.
 gitweb/static/js/blame_incremental.js |   13 ++++---------
 1 files changed, 4 insertions(+), 9 deletions(-)
diff --git a/gitweb/static/js/blame_incremental.js b/gitweb/static/js/blame_incremental.js
index 4841805..27955ec 100644
--- a/gitweb/static/js/blame_incremental.js
+++ b/gitweb/static/js/blame_incremental.js
@@ -603,21 +603,16 @@ function handleResponse() {
 		return;
 	}
 
-	// extract new whole (complete) lines, and process them
-	while (xhr.prevDataLength !== xhr.responseText.length) {
-		if (xhr.readyState === 4 &&
-		    xhr.prevDataLength === xhr.responseText.length) {
-			break;
-		}
 
+	// extract new whole (complete) lines, and process them
+	if (xhr.prevDataLength !== xhr.responseText.length) {
 		xhr.prevDataLength = xhr.responseText.length;
 		var unprocessed = xhr.responseText.substring(xhr.nextReadPos);
 		xhr.nextReadPos = processData(unprocessed, xhr.nextReadPos);
-	} // end while
+	}
 
 	// did we finish work?
-	if (xhr.readyState === 4 &&
-	    xhr.prevDataLength === xhr.responseText.length) {
+	if (xhr.readyState === 4) {
 		responseLoaded(xhr);
 	}
 }
-- 
1.7.5
Previous: Jakub NarebskiNext: Jakub Narebski
Message 3 of 5 in “gitweb: Improving blame_incremental.js”
  1. 0/3 gitweb: Improving blame_incremental.jsJakub Narebski, May 27, 2011
  2. 1/3 gitweb.js: No need for inProgress in blame_incremental.jsJakub Narebski, May 27, 2011
  3. 2/3 gitweb.js: No need for loop in blame_incremental's handleResponse()Jakub Narebski, May 27, 2011
  4. 3/3 gitweb.js: use setTimeout rather than setInterval in blame_incremental.jsJakub Narebski, May 27, 2011
  5. Jakub NarebskiMay 27, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.