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

[PATCH 1/2] xdiff: add recs_match helper function

From
Stefan Beller <sbeller@google.com>
Date
Apr 19, 2016, 15:21 UTC
Message-ID
<1461079290-6523-2-git-send-email-sbeller@google.com>
In-Reply-To
<1461079290-6523-1-git-send-email-sbeller@google.com>
From: Jacob Keller <jacob.keller@gmail.com>

It is a common pattern in xdl_change_compact to check that hashes and strings match. The resulting code to perform this change causes very long lines and makes it hard to follow the intention. Introduce a helper function recs_match which performs both checks to increase code readability.

Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 xdiff/xdiffi.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/xdiff/xdiffi.c b/xdiff/xdiffi.c
index 2358a2d..748eeb9 100644
--- a/xdiff/xdiffi.c
+++ b/xdiff/xdiffi.c
@@ -400,6 +400,14 @@ static xdchange_t *xdl_add_change(xdchange_t *xscr, long i1, long i2, long chg1,
 }
 
 
+static int recs_match(xrecord_t **recs, long ixs, long ix, long flags)
+{
+	return (recs[ixs]->ha == recs[ix]->ha &&
+		xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size,
+			     recs[ix]->ptr, recs[ix]->size,
+			     flags));
+}
+
 int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
 	long ix, ixo, ixs, ixref, grpsiz, nrec = xdf->nrec;
 	char *rchg = xdf->rchg, *rchgo = xdfo->rchg;
@@ -442,8 +450,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
 			 * the last line of the current change group, shift backward
 			 * the group.
 			 */
-			while (ixs > 0 && recs[ixs - 1]->ha == recs[ix - 1]->ha &&
-			       xdl_recmatch(recs[ixs - 1]->ptr, recs[ixs - 1]->size, recs[ix - 1]->ptr, recs[ix - 1]->size, flags)) {
+			while (ixs > 0 && recs_match(recs, ixs - 1, ix - 1, flags)) {
 				rchg[--ixs] = 1;
 				rchg[--ix] = 0;
 
@@ -470,8 +477,7 @@ int xdl_change_compact(xdfile_t *xdf, xdfile_t *xdfo, long flags) {
 			 * the line next of the current change group, shift forward
 			 * the group.
 			 */
-			while (ix < nrec && recs[ixs]->ha == recs[ix]->ha &&
-			       xdl_recmatch(recs[ixs]->ptr, recs[ixs]->size, recs[ix]->ptr, recs[ix]->size, flags)) {
+			while (ix < nrec && recs_match(recs, ixs, ix, flags)) {
 				rchg[ixs++] = 0;
 				rchg[ix++] = 1;
 
-- 
2.4.11.2.g96ed4e5.dirty
Previous: Stefan BellerNext: Stefan Beller
Message 2 of 19 in “[PATCHv5 0/2] xdiff: implement empty line chunk heuristic”
  1. Stefan BellerApr 19, 2016
  2. 1/2 xdiff: add recs_match helper functionStefan Beller, Apr 19, 2016
  3. 2/2 xdiff: implement empty line chunk heuristicStefan Beller, Apr 19, 2016
  4. Junio C HamanoApr 19, 2016
  5. Jeff KingApr 20, 2016
  6. Jeff KingApr 20, 2016
  7. Stefan BellerApr 20, 2016
  8. Junio C HamanoApr 29, 2016
  9. Jacob KellerApr 29, 2016
  10. Junio C HamanoApr 29, 2016
  11. Stefan BellerApr 29, 2016
  12. Keller, Jacob EApr 29, 2016
  13. Stefan BellerApr 29, 2016
  14. Keller, Jacob EApr 29, 2016
  15. Junio C HamanoMay 2, 2016
  16. Stefan BellerMay 2, 2016
  17. Jeff KingMay 2, 2016
  18. Jacob KellerMay 3, 2016
  19. Jeff KingApr 30, 2016

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.