- Timestamp:
- 04/07/15 04:20:53 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/frams/util/sstring.cpp
r286 r347 80 80 if (chlen<size) 81 81 { 82 mem cpy(txt,ch,chlen);82 memmove(txt,ch,chlen); 83 83 } 84 84 else … … 97 97 void SBuf::append(const char *ch,int chlen) 98 98 { // doesn't check anything! 99 mem cpy(txt+used,ch,chlen);99 memmove(txt+used,ch,chlen); 100 100 used+=chlen; 101 101 txt[used]=0; … … 108 108 txt=(char*)realloc(txt,needed+1); 109 109 size=needed; 110 }111 112 //////////////////////////////////////////////////113 // to be moved somewhere else?114 // public domain source: http://isthe.com/chongo/src/fnv115 typedef uint32_t Fnv32_t;116 117 #define FNV_32_PRIME ((Fnv32_t)0x01000193)118 #define FNV1_32_INIT ((Fnv32_t)0x811c9dc5)119 #define FNV1_32A_INIT FNV1_32_INIT120 121 Fnv32_t fnv_32a_buf(void *buf, size_t len, Fnv32_t hval)122 {123 unsigned char *bp = (unsigned char *)buf; /* start of buffer */124 unsigned char *be = bp + len; /* beyond end of buffer */125 126 while (bp < be) {127 128 /* xor the bottom with the current octet */129 hval ^= (Fnv32_t)*bp++;130 131 /* multiply by the 32 bit FNV magic prime mod 2^32 */132 #if defined(NO_FNV_GCC_OPTIMIZATION)133 hval *= FNV_32_PRIME;134 #else135 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24);136 #endif137 138 }139 140 /* return our new hash value */141 return hval;142 }143 //////////////////////////////////////////////////144 145 uint32_t SBuf::hash() const146 {147 return fnv_32a_buf(txt,used,FNV1_32A_INIT);148 110 } 149 111 … … 308 270 detachEmpty(chlen); 309 271 REF_UNLOCK; 310 mem cpy(buf->txt,ch,chlen);272 memmove(buf->txt,ch,chlen); 311 273 buf->txt[chlen]=0; buf->used=chlen; 312 274 } … … 463 425 464 426 #endif //#ifdef SSTRING_SIMPLE 427 428 ////////////////////////////////////////////////// 429 // to be moved somewhere else? 430 // public domain source: http://isthe.com/chongo/src/fnv 431 typedef uint32_t Fnv32_t; 432 433 #define FNV_32_PRIME ((Fnv32_t)0x01000193) 434 #define FNV1_32_INIT ((Fnv32_t)0x811c9dc5) 435 #define FNV1_32A_INIT FNV1_32_INIT 436 437 Fnv32_t fnv_32a_buf(void *buf, size_t len, Fnv32_t hval) 438 { 439 unsigned char *bp = (unsigned char *)buf; /* start of buffer */ 440 unsigned char *be = bp + len; /* beyond end of buffer */ 441 442 while (bp < be) { 443 444 /* xor the bottom with the current octet */ 445 hval ^= (Fnv32_t)*bp++; 446 447 /* multiply by the 32 bit FNV magic prime mod 2^32 */ 448 #if defined(NO_FNV_GCC_OPTIMIZATION) 449 hval *= FNV_32_PRIME; 450 #else 451 hval += (hval<<1) + (hval<<4) + (hval<<7) + (hval<<8) + (hval<<24); 452 #endif 453 454 } 455 456 /* return our new hash value */ 457 return hval; 458 } 459 ////////////////////////////////////////////////// 460 461 #ifdef SSTRING_SIMPLE 462 uint32_t SString::hash() const 463 { 464 return fnv_32a_buf(txt,used,FNV1_32A_INIT); 465 } 466 #else 467 uint32_t SBuf::hash() const 468 { 469 return fnv_32a_buf(txt,used,FNV1_32A_INIT); 470 } 471 #endif
Note: See TracChangeset
for help on using the changeset viewer.