GetMetaStrBytes converts MetaString to optimized MetaStringBytes
(metastr *meta.MetaString)
| 236 | |
| 237 | // GetMetaStrBytes converts MetaString to optimized MetaStringBytes |
| 238 | func (r *MetaStringResolver) GetMetaStrBytes(metastr *meta.MetaString) *MetaStringBytes { |
| 239 | // Check cache first |
| 240 | if m, exists := r.metaStrToMetaStrBytes[metastr]; exists { |
| 241 | return m |
| 242 | } |
| 243 | |
| 244 | // Compute hash based on string size |
| 245 | var hashcode int64 |
| 246 | data := metastr.GetEncodedBytes() |
| 247 | length := len(data) |
| 248 | |
| 249 | if length == 0 { |
| 250 | r.metaStrToMetaStrBytes[metastr] = emptyMetaStringBytes |
| 251 | return emptyMetaStringBytes |
| 252 | } |
| 253 | if length <= SmallStringThreshold { |
| 254 | // Small string: use direct bytes as hash components |
| 255 | words := smallMetaStringWords(data) |
| 256 | hashcode = computeSmallMetaStringHash(words, length, metastr.GetEncoding()) |
| 257 | } else { |
| 258 | // Large string: use MurmurHash3 |
| 259 | h64 := Murmur3Sum64WithSeed(data, 47) |
| 260 | hashcode = int64((h64 >> 8) << 8) |
| 261 | hashcode |= int64(metastr.GetEncoding()) |
| 262 | } |
| 263 | |
| 264 | // Create and cache new instance |
| 265 | m := NewMetaStringBytes(data, hashcode) |
| 266 | r.metaStrToMetaStrBytes[metastr] = m |
| 267 | return m |
| 268 | } |
| 269 | |
| 270 | // ComputeMetaStringHash computes the hashcode for meta string bytes |
| 271 | func ComputeMetaStringHash(data []byte, encoding meta.Encoding) int64 { |