about summary refs log tree commit diff
path: root/src/malloc
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2015-03-04 10:48:00 -0500
committerRich Felker <dalias@aerifal.cx>2015-03-04 10:48:00 -0500
commit064898cfe2233526e7639c21e780695be5ece257 (patch)
treeda2e86a12553630c757be6438838bc81f8e11195 /src/malloc
parent6de071a0be00ec2ff08af3c89c7caaa20f1044d7 (diff)
downloadmusl-064898cfe2233526e7639c21e780695be5ece257.tar.gz
musl-064898cfe2233526e7639c21e780695be5ece257.tar.xz
musl-064898cfe2233526e7639c21e780695be5ece257.zip
remove useless check of bin match in malloc
this re-check idiom seems to have been copied from the alloc_fwd and
alloc_rev functions, which guess a bin based on non-synchronized
memory access to adjacent chunk headers then need to confirm, after
locking the bin, that the chunk is actually in the bin they locked.

the check being removed, however, was being performed on a chunk
obtained from the already-locked bin. there is no race to account for
here; the check could only fail in the event of corrupt free lists,
and even then it would not catch them but simply continue running.

since the bin_index function is mildly expensive, it seems preferable
to remove the check rather than trying to convert it into a useful
consistency check. casual testing shows a 1-5% reduction in run time.
Diffstat (limited to 'src/malloc')
-rw-r--r--src/malloc/malloc.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
index 4f61807b..d4de2dc1 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -364,7 +364,7 @@ void *malloc(size_t n)
 		j = first_set(mask);
 		lock_bin(j);
 		c = mal.bins[j].head;
-		if (c != BIN_TO_CHUNK(j) && j == bin_index(c->csize)) {
+		if (c != BIN_TO_CHUNK(j)) {
 			if (!pretrim(c, n, i, j)) unbin(c, j);
 			unlock_bin(j);
 			break;