mirror of
				https://github.com/TeaOSLab/EdgeNode.git
				synced 2025-11-04 07:40:56 +08:00 
			
		
		
		
	优化WAF性能
This commit is contained in:
		@@ -7,9 +7,20 @@ const (
 | 
			
		||||
	prime64  uint64 = 1099511628211
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Hash
 | 
			
		||||
// HashString
 | 
			
		||||
// 非unique Hash
 | 
			
		||||
func Hash(key string) uint64 {
 | 
			
		||||
func HashString(key string) uint64 {
 | 
			
		||||
	var hash = offset64
 | 
			
		||||
	for _, b := range key {
 | 
			
		||||
		hash ^= uint64(b)
 | 
			
		||||
		hash *= prime64
 | 
			
		||||
	}
 | 
			
		||||
	return hash
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Hash
 | 
			
		||||
// 非unique Hash
 | 
			
		||||
func Hash(key []byte) uint64 {
 | 
			
		||||
	var hash = offset64
 | 
			
		||||
	for _, b := range key {
 | 
			
		||||
		hash ^= uint64(b)
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@ import (
 | 
			
		||||
 | 
			
		||||
func TestHash(t *testing.T) {
 | 
			
		||||
	for _, key := range []string{"costarring", "liquid", "hello"} {
 | 
			
		||||
		var h = fnv.Hash(key)
 | 
			
		||||
		var h = fnv.HashString(key)
 | 
			
		||||
		t.Log(key + " => " + types.String(h))
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user