| 611 | } |
| 612 | |
| 613 | void VectorHasher::copyStringToLocal(const UniqueValue* unique) { |
| 614 | auto size = unique->size(); |
| 615 | if (size <= sizeof(int64_t)) { |
| 616 | return; |
| 617 | } |
| 618 | if (distinctStringsBytes_ > kMaxDistinctStringsBytes) { |
| 619 | setDistinctOverflow(); |
| 620 | return; |
| 621 | } |
| 622 | if (uniqueValuesStorage_.empty()) { |
| 623 | uniqueValuesStorage_.emplace_back(); |
| 624 | uniqueValuesStorage_.back().reserve(std::max(kStringBufferUnitSize, size)); |
| 625 | distinctStringsBytes_ += uniqueValuesStorage_.back().capacity(); |
| 626 | } |
| 627 | auto str = &uniqueValuesStorage_.back(); |
| 628 | if (str->size() + size > str->capacity()) { |
| 629 | uniqueValuesStorage_.emplace_back(); |
| 630 | uniqueValuesStorage_.back().reserve(std::max(kStringBufferUnitSize, size)); |
| 631 | distinctStringsBytes_ += uniqueValuesStorage_.back().capacity(); |
| 632 | str = &uniqueValuesStorage_.back(); |
| 633 | } |
| 634 | auto start = str->size(); |
| 635 | str->resize(start + size); |
| 636 | memcpy(str->data() + start, reinterpret_cast<char*>(unique->data()), size); |
| 637 | const_cast<UniqueValue*>(unique)->setData( |
| 638 | reinterpret_cast<int64_t>(str->data() + start)); |
| 639 | } |
| 640 | |
| 641 | void VectorHasher::setDistinctOverflow() { |
| 642 | distinctOverflow_ = true; |