MySQL 8.4.2
Source Code Documentation
histogram_utility.h
Go to the documentation of this file.
1#ifndef HISTOGRAMS_HISTOGRAM_UTILITY_INCLUDED
2#define HISTOGRAMS_HISTOGRAM_UTILITY_INCLUDED
3
4/* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License, version 2.0,
8 as published by the Free Software Foundation.
9
10 This program is designed to work with certain software (including
11 but not limited to OpenSSL) that is licensed under separate terms,
12 as designated in a particular file or component or in included license
13 documentation. The authors of MySQL hereby grant you an additional
14 permission to link the program and your derivative works with the
15 separately licensed software that they have either included with
16 the program or referenced in the documentation.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License, version 2.0, for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
26
27#include "my_alloc.h"
28#include "sql_string.h"
29
30namespace histograms {
31
32/**
33 Returns a deep copy of the input argument. In case T has heap-allocated data
34 it is copied onto the supplied mem_root.
35
36 @note This function is only intended to be used to copy the values in
37 histogram buckets and does not provide general support for deep copying
38 arbitrary types.
39
40 @param src The value to be copied.
41 @param mem_root The MEM_ROOT to copy heap-allocated data onto.
42 @param[out] error Set to true if an error occurs.
43
44 @return A deep copy of the input argument.
45*/
46template <typename T>
47T DeepCopy(const T &src, [[maybe_unused]] MEM_ROOT *mem_root,
48 [[maybe_unused]] bool *error) {
49 return src;
50}
51
52template <>
53inline String DeepCopy(const String &src, MEM_ROOT *mem_root, bool *error) {
54 char *dst = src.dup(mem_root);
55 if (dst == nullptr) {
56 *error = true;
57 return String();
58 }
59 return String(dst, src.length(), src.charset());
60}
61
62} // namespace histograms
63
64#endif
Using this class is fraught with peril, and you need to be very careful when doing so.
Definition: sql_string.h:167
const CHARSET_INFO * charset() const
Definition: sql_string.h:240
char * dup(MEM_ROOT *root) const
Make a zero-terminated copy of our value,allocated in the specified MEM_ROOT.
Definition: sql_string.cc:1001
size_t length() const
Definition: sql_string.h:241
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
void error(const char *format,...)
borrowable::binary::String< true > String
Definition: classic_protocol_binary.h:323
Definition: column_statistics.h:34
T DeepCopy(const T &src, MEM_ROOT *mem_root, bool *error)
Returns a deep copy of the input argument.
Definition: histogram_utility.h:47
Our own string classes, used pervasively throughout the executor.
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83