threads / patch / 35936

patchbuiltin/blame.c::find_copy_in_blob: no need to scan for region end

Subject: [PATCH] builtin/blame.c::find_copy_in_blob: no need to scan for region end

## tl;dr

2 messages between Feb 22, 2014 and Feb 25, 2014. Diffs are folded; open one to read it.

replies: 1people: 2as markdown or json

David Kastrup· Feb 22, 2014, 16:02 UTC · lore
The region end can be looked up just like its beginning.
Signed-off-by: David Kastrup <dak@gnu.org>
---
 builtin/blame.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)
Show changes to builtin/blame.c +1 −8
diff --git a/builtin/blame.c b/builtin/blame.c
index e44a6bb..96716dd 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -939,7 +939,6 @@ static void find_copy_in_blob(struct scoreboard *sb,
 			      mmfile_t *file_p)
 {
 	const char *cp;
-	int cnt;
 	mmfile_t file_o;
 	struct handle_split_cb_data d;
 
@@ -950,13 +949,7 @@ static void find_copy_in_blob(struct scoreboard *sb,
 	 */
 	cp = nth_line(sb, ent->lno);
 	file_o.ptr = (char *) cp;
-	cnt = ent->num_lines;
-
-	while (cnt && cp < sb->final_buf + sb->final_buf_size) {
-		if (*cp++ == '\n')
-			cnt--;
-	}
-	file_o.size = cp - file_o.ptr;
+	file_o.size = nth_line(sb, ent->lno + ent->num_lines) - cp;
 
 	/*
 	 * file_o is a part of final image we are annotating.
-- 
1.8.3.2
Junio C Hamano· Feb 25, 2014, 17:51 UTC · re: David Kastrup · lore

Re: [PATCH] builtin/blame.c::find_copy_in_blob: no need to scan for region end

David Kastrup <dak@gnu.org> writes:
Show 6 quoted lines
> The region end can be looked up just like its beginning.
>
> Signed-off-by: David Kastrup <dak@gnu.org>
> ---
>  builtin/blame.c | 9 +--------
>  1 file changed, 1 insertion(+), 8 deletions(-)
Yay, code reduction!  Thanks.
Show 27 quoted lines
> diff --git a/builtin/blame.c b/builtin/blame.c
> index e44a6bb..96716dd 100644
> --- a/builtin/blame.c
> +++ b/builtin/blame.c
> @@ -939,7 +939,6 @@ static void find_copy_in_blob(struct scoreboard *sb,
>  			      mmfile_t *file_p)
>  {
>  	const char *cp;
> -	int cnt;
>  	mmfile_t file_o;
>  	struct handle_split_cb_data d;
>  
> @@ -950,13 +949,7 @@ static void find_copy_in_blob(struct scoreboard *sb,
>  	 */
>  	cp = nth_line(sb, ent->lno);
>  	file_o.ptr = (char *) cp;
> -	cnt = ent->num_lines;
> -
> -	while (cnt && cp < sb->final_buf + sb->final_buf_size) {
> -		if (*cp++ == '\n')
> -			cnt--;
> -	}
> -	file_o.size = cp - file_o.ptr;
> +	file_o.size = nth_line(sb, ent->lno + ent->num_lines) - cp;
>  
>  	/*
>  	 * file_o is a part of final image we are annotating.

← back to recent threads