[Bf-blender-cvs] [83fe139] master: Undo: use system memcmp

Campbell Barton noreply at git.blender.org
Fri Jul 8 07:53:05 CEST 2016


Commit: 83fe139b2b9c37db50c14833cb38877b999db6de
Author: Campbell Barton
Date:   Fri Jul 8 15:42:50 2016 +1000
Branches: master
https://developer.blender.org/rB83fe139b2b9c37db50c14833cb38877b999db6de

Undo: use system memcmp

`my_memcmp` didn't work properly comparing memory sizes not aligned to 4 bytes,
this worked while we used guarded-alloc (which always wrote a guard at the end of each allocation).
Since moving to lockfree allocator it could read uninitialized memory.

It also consistently performed ~10-30% worse then glibc's.
This is typically well optimized, no need to do ourselves.

===================================================================

M	source/blender/blenloader/intern/undofile.c

===================================================================

diff --git a/source/blender/blenloader/intern/undofile.c b/source/blender/blenloader/intern/undofile.c
index d0dc9a8..c191e48 100644
--- a/source/blender/blenloader/intern/undofile.c
+++ b/source/blender/blenloader/intern/undofile.c
@@ -80,20 +80,6 @@ void BLO_memfile_merge(MemFile *first, MemFile *second)
 	BLO_memfile_free(first);
 }
 
-static int my_memcmp(const int *mem1, const int *mem2, const int len)
-{
-	register int a = len;
-	register const int *mema = mem1;
-	register const int *memb = mem2;
-	
-	while (a--) {
-		if (*mema != *memb) return 1;
-		mema++;
-		memb++;
-	}
-	return 0;
-}
-
 void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsigned int size)
 {
 	static MemFileChunk *compchunk = NULL;
@@ -118,7 +104,7 @@ void memfile_chunk_add(MemFile *compare, MemFile *current, const char *buf, unsi
 	/* we compare compchunk with buf */
 	if (compchunk) {
 		if (compchunk->size == curchunk->size) {
-			if (my_memcmp((int *)compchunk->buf, (const int *)buf, size / 4) == 0) {
+			if (memcmp(compchunk->buf, buf, size) == 0) {
 				curchunk->buf = compchunk->buf;
 				curchunk->ident = 1;
 			}




More information about the Bf-blender-cvs mailing list