[PATCH] xdiff/xmerge.c: use memset() instead of explicit for-loop

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



memset() is heavily optimized, and resulting assembler code
is about 150 lines less for that file.

Signed-off-by: Alexey Mahotkin <squadette@xxxxxxxxx>
---
 xdiff/xmerge.c |   17 ++++++++---------
 1 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 16dd9ac..6d6fc1b 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -152,7 +152,6 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 	int marker1_size = (name1 ? strlen(name1) + 1 : 0);
 	int marker2_size = (name2 ? strlen(name2) + 1 : 0);
 	int marker3_size = (name3 ? strlen(name3) + 1 : 0);
-	int j;
 
 	if (marker_size <= 0)
 		marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
@@ -164,8 +163,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 	if (!dest) {
 		size += marker_size + 1 + marker1_size;
 	} else {
-		for (j = 0; j < marker_size; j++)
-			dest[size++] = '<';
+		memset(dest + size, '<', marker_size);
+		size += marker_size;
 		if (marker1_size) {
 			dest[size] = ' ';
 			memcpy(dest + size + 1, name1, marker1_size - 1);
@@ -183,8 +182,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 		if (!dest) {
 			size += marker_size + 1 + marker3_size;
 		} else {
-			for (j = 0; j < marker_size; j++)
-				dest[size++] = '|';
+			memset(dest + size, '|', marker_size);
+			size += marker_size;
 			if (marker3_size) {
 				dest[size] = ' ';
 				memcpy(dest + size + 1, name3, marker3_size - 1);
@@ -199,8 +198,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 	if (!dest) {
 		size += marker_size + 1;
 	} else {
-		for (j = 0; j < marker_size; j++)
-			dest[size++] = '=';
+		memset(dest + size, '=', marker_size);
+		size += marker_size;
 		dest[size++] = '\n';
 	}
 
@@ -210,8 +209,8 @@ static int fill_conflict_hunk(xdfenv_t *xe1, const char *name1,
 	if (!dest) {
 		size += marker_size + 1 + marker2_size;
 	} else {
-		for (j = 0; j < marker_size; j++)
-			dest[size++] = '>';
+		memset(dest + size, '>', marker_size);
+		size += marker_size;
 		if (marker2_size) {
 			dest[size] = ' ';
 			memcpy(dest + size + 1, name2, marker2_size - 1);
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]