mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-12-15 10:52:30 +00:00
21 lines
547 B
C++
21 lines
547 B
C++
#pragma once
|
|
|
|
#include <string.h>
|
|
#include <string>
|
|
#include <base/StringRef.h>
|
|
|
|
/** Copy string value into Arena.
|
|
* Arena should support method:
|
|
* char * alloc(size_t size).
|
|
*/
|
|
template <typename Arena>
|
|
inline StringRef copyStringInArena(Arena & arena, StringRef value)
|
|
{
|
|
size_t value_size = value.size;
|
|
char * place_for_key = arena.alloc(value_size);
|
|
memcpy(reinterpret_cast<void *>(place_for_key), reinterpret_cast<const void *>(value.data), value_size);
|
|
StringRef result{place_for_key, value_size};
|
|
|
|
return result;
|
|
}
|