aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/Common/ArenaUtils.h
blob: 0c31b1b253389034d265fa21335e9539c858ac90 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#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;
}