浏览代码

Optimize _dl_elf_hash(), both smaller and faster. Mostly
taken from glibc.

Joakim Tjernlund 20 年之前
父节点
当前提交
a55a088d1a
共有 1 个文件被更改,包括 10 次插入4 次删除
  1. 10 4
      ldso/ldso/dl-hash.c

+ 10 - 4
ldso/ldso/dl-hash.c

@@ -59,14 +59,20 @@ struct dyn_elf *_dl_handles = NULL;
  * it to decode the hash table.  */
 static inline unsigned long _dl_elf_hash(const unsigned char *name)
 {
-	unsigned long hash = 0;
+	unsigned long hash=0;
 	unsigned long tmp;
 
 	while (*name) {
 		hash = (hash << 4) + *name++;
-		if ((tmp = hash & 0xf0000000))
-			hash ^= tmp >> 24;
-		hash &= ~tmp;
+		tmp = hash & 0xf0000000;
+		/* The algorithm specified in the ELF ABI is as follows:
+		   if (tmp != 0)
+		       hash ^= tmp >> 24;
+		   hash &= ~tmp;
+		   But the following is equivalent and a lot
+		   faster, especially on modern processors. */
+		hash ^= tmp;
+		hash ^= tmp >> 24;
 	}
 	return hash;
 }