Coverage Report

Created: 2026-08-14 08:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/rocksdb/util/coding.h
Line
Count
Source
1
//  Copyright (c) 2011-present, Facebook, Inc.  All rights reserved.
2
//  This source code is licensed under both the GPLv2 (found in the
3
//  COPYING file in the root directory) and Apache 2.0 License
4
//  (found in the LICENSE.Apache file in the root directory).
5
//
6
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
7
// Use of this source code is governed by a BSD-style license that can be
8
// found in the LICENSE file. See the AUTHORS file for names of contributors.
9
//
10
// Encoding independent of machine byte order:
11
// * Fixed-length numbers are encoded with least-significant byte first
12
//   (little endian, native order on Intel and others)
13
// * In addition we support variable length "varint" encoding
14
// * Strings are encoded prefixed by their length in varint format
15
//
16
// Some related functions are provided in coding_lean.h
17
18
#pragma once
19
#include <algorithm>
20
#include <string>
21
#include <type_traits>
22
23
#include "port/port.h"
24
#include "rocksdb/slice.h"
25
#include "util/cast_util.h"
26
#include "util/coding_lean.h"
27
28
// Some processors does not allow unaligned access to memory
29
#if defined(__sparc)
30
#define PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED
31
#endif
32
33
namespace ROCKSDB_NAMESPACE {
34
35
// The maximum length of a varint in bytes for 64-bit.
36
const uint32_t kMaxVarint64Length = 10;
37
38
// Standard Put... routines append to a string
39
void PutFixed16(std::string* dst, uint16_t value);
40
void PutFixed32(std::string* dst, uint32_t value);
41
void PutFixed64(std::string* dst, uint64_t value);
42
43
template <typename... Args>
44
void PutVarint32(std::string* dst, Args... args);
45
void PutVarint64(std::string* dst, uint64_t value);
46
void PutVarint64Varint64(std::string* dst, uint64_t value1, uint64_t value2);
47
void PutVarint32Varint64(std::string* dst, uint32_t value1, uint64_t value2);
48
void PutVarint32Varint32Varint64(std::string* dst, uint32_t value1,
49
                                 uint32_t value2, uint64_t value3);
50
void PutLengthPrefixedSlice(std::string* dst, const Slice& value);
51
void PutLengthPrefixedSliceParts(std::string* dst,
52
                                 const SliceParts& slice_parts);
53
void PutLengthPrefixedSlicePartsWithPadding(std::string* dst,
54
                                            const SliceParts& slice_parts,
55
                                            size_t pad_sz);
56
57
// Standard Get... routines parse a value from the beginning of a Slice
58
// and advance the slice past the parsed value.
59
bool GetFixed64(Slice* input, uint64_t* value);
60
bool GetFixed32(Slice* input, uint32_t* value);
61
bool GetFixed16(Slice* input, uint16_t* value);
62
bool GetVarint32(Slice* input, uint32_t* value);
63
bool GetVarint64(Slice* input, uint64_t* value);
64
bool GetVarsignedint64(Slice* input, int64_t* value);
65
bool GetLengthPrefixedSlice(Slice* input, Slice* result);
66
// This function assumes data is well-formed.
67
Slice GetLengthPrefixedSlice(const char* data);
68
69
Slice GetSliceUntil(Slice* slice, char delimiter);
70
71
// Borrowed from
72
// https://github.com/facebook/fbthrift/blob/449a5f77f9f9bae72c9eb5e78093247eef185c04/thrift/lib/cpp/util/VarintUtils-inl.h#L202-L208
73
7.18k
constexpr inline uint64_t i64ToZigzag(const int64_t l) {
74
7.18k
  return (static_cast<uint64_t>(l) << 1) ^ static_cast<uint64_t>(l >> 63);
75
7.18k
}
76
0
inline int64_t zigzagToI64(uint64_t n) {
77
0
  return (n >> 1) ^ -static_cast<int64_t>(n & 1);
78
0
}
79
80
// Pointer-based variants of GetVarint...  These either store a value
81
// in *v and return a pointer just past the parsed value, or return
82
// nullptr on error.  These routines only look at bytes in the range
83
// [p..limit-1]
84
const char* GetVarint32Ptr(const char* p, const char* limit, uint32_t* v);
85
const char* GetVarint64Ptr(const char* p, const char* limit, uint64_t* v);
86
inline const char* GetVarsignedint64Ptr(const char* p, const char* limit,
87
0
                                        int64_t* value) {
88
0
  uint64_t u = 0;
89
0
  const char* ret = GetVarint64Ptr(p, limit, &u);
90
0
  *value = zigzagToI64(u);
91
0
  return ret;
92
0
}
93
94
// Returns the length of the varint32 or varint64 encoding of "v"
95
uint16_t VarintLength(uint64_t v);
96
97
// Lower-level versions of Put... that write directly into a character buffer
98
// and return a pointer just past the last byte written.
99
// REQUIRES: dst has enough space for the value being written
100
char* EncodeVarint32(char* dst, uint32_t value);
101
char* EncodeVarint64(char* dst, uint64_t value);
102
103
// Internal routine for use by fallback path of GetVarint32Ptr
104
const char* GetVarint32PtrFallback(const char* p, const char* limit,
105
                                   uint32_t* value);
106
inline const char* GetVarint32Ptr(const char* p, const char* limit,
107
30.4M
                                  uint32_t* value) {
108
30.4M
  if (p < limit) {
109
29.9M
    uint32_t result = *(lossless_cast<const unsigned char*>(p));
110
29.9M
    if ((result & 128) == 0) {
111
26.4M
      *value = result;
112
26.4M
      return p + 1;
113
26.4M
    }
114
29.9M
  }
115
3.99M
  return GetVarint32PtrFallback(p, limit, value);
116
30.4M
}
117
118
// Pull the last 8 bits and cast it to a character
119
0
inline void PutFixed16(std::string* dst, uint16_t value) {
120
0
  if (port::kLittleEndian) {
121
0
    dst->append(const_cast<const char*>(reinterpret_cast<char*>(&value)),
122
0
                sizeof(value));
123
0
  } else {
124
0
    char buf[sizeof(value)];
125
0
    EncodeFixed16(buf, value);
126
0
    dst->append(buf, sizeof(buf));
127
0
  }
128
0
}
129
130
345k
inline void PutFixed32(std::string* dst, uint32_t value) {
131
345k
  if (port::kLittleEndian) {
132
345k
    dst->append(const_cast<const char*>(reinterpret_cast<char*>(&value)),
133
345k
                sizeof(value));
134
345k
  } else {
135
0
    char buf[sizeof(value)];
136
0
    EncodeFixed32(buf, value);
137
0
    dst->append(buf, sizeof(buf));
138
0
  }
139
345k
}
140
141
97.2M
inline void PutFixed64(std::string* dst, uint64_t value) {
142
97.2M
  if (port::kLittleEndian) {
143
97.2M
    dst->append(const_cast<const char*>(reinterpret_cast<char*>(&value)),
144
97.2M
                sizeof(value));
145
97.2M
  } else {
146
0
    char buf[sizeof(value)];
147
0
    EncodeFixed64(buf, value);
148
0
    dst->append(buf, sizeof(buf));
149
0
  }
150
97.2M
}
151
152
template <typename... Args>
153
5.55M
inline void PutVarint32(std::string* dst, Args... args) {
154
5.55M
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
5.55M
                "All arguments must be convertible to uint32_t");
156
5.55M
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
5.55M
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
5.55M
  char* ptr = buf;
159
5.55M
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
5.55M
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
5.55M
}
void rocksdb::PutVarint32<unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, unsigned int)
Line
Count
Source
153
2.89M
inline void PutVarint32(std::string* dst, Args... args) {
154
2.89M
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
2.89M
                "All arguments must be convertible to uint32_t");
156
2.89M
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
2.89M
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
2.89M
  char* ptr = buf;
159
2.89M
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
2.89M
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
2.89M
}
void rocksdb::PutVarint32<rocksdb::Tag>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::Tag)
Line
Count
Source
153
523k
inline void PutVarint32(std::string* dst, Args... args) {
154
523k
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
523k
                "All arguments must be convertible to uint32_t");
156
523k
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
523k
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
523k
  char* ptr = buf;
159
523k
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
523k
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
523k
}
void rocksdb::PutVarint32<rocksdb::Tag, unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::Tag, unsigned int)
Line
Count
Source
153
146k
inline void PutVarint32(std::string* dst, Args... args) {
154
146k
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
146k
                "All arguments must be convertible to uint32_t");
156
146k
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
146k
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
146k
  char* ptr = buf;
159
146k
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
146k
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
146k
}
Unexecuted instantiation: void rocksdb::PutVarint32<int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, int)
void rocksdb::PutVarint32<rocksdb::NewFileCustomTag>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::NewFileCustomTag)
Line
Count
Source
153
802k
inline void PutVarint32(std::string* dst, Args... args) {
154
802k
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
802k
                "All arguments must be convertible to uint32_t");
156
802k
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
802k
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
802k
  char* ptr = buf;
159
802k
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
802k
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
802k
}
Unexecuted instantiation: void rocksdb::PutVarint32<rocksdb::SubcompactionProgressPerLevelCustomTag>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::SubcompactionProgressPerLevelCustomTag)
Unexecuted instantiation: void rocksdb::PutVarint32<rocksdb::SubcompactionProgressCustomTag>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::SubcompactionProgressCustomTag)
Unexecuted instantiation: void rocksdb::PutVarint32<rocksdb::BlobFileAddition::CustomFieldTags>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::BlobFileAddition::CustomFieldTags)
Unexecuted instantiation: void rocksdb::PutVarint32<rocksdb::BlobFileGarbage::CustomFieldTags>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, rocksdb::BlobFileGarbage::CustomFieldTags)
void rocksdb::PutVarint32<unsigned int, unsigned int, unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, unsigned int, unsigned int, unsigned int)
Line
Count
Source
153
1.13M
inline void PutVarint32(std::string* dst, Args... args) {
154
1.13M
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
1.13M
                "All arguments must be convertible to uint32_t");
156
1.13M
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
1.13M
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
1.13M
  char* ptr = buf;
159
1.13M
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
1.13M
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
1.13M
}
void rocksdb::PutVarint32<unsigned int, unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, unsigned int, unsigned int)
Line
Count
Source
153
57.8k
inline void PutVarint32(std::string* dst, Args... args) {
154
57.8k
  static_assert((std::is_convertible_v<Args, uint32_t> && ...),
155
57.8k
                "All arguments must be convertible to uint32_t");
156
57.8k
  constexpr size_t kMaxBytesPerVarint32 = 5;
157
57.8k
  char buf[sizeof...(args) * kMaxBytesPerVarint32];
158
57.8k
  char* ptr = buf;
159
57.8k
  ((ptr = EncodeVarint32(ptr, static_cast<uint32_t>(args))), ...);
160
57.8k
  dst->append(buf, static_cast<size_t>(ptr - buf));
161
57.8k
}
Unexecuted instantiation: void rocksdb::PutVarint32<unsigned int, unsigned int, unsigned int, unsigned int>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*, unsigned int, unsigned int, unsigned int, unsigned int)
162
163
2.98M
inline char* EncodeVarint64(char* dst, uint64_t v) {
164
2.98M
  static const unsigned int B = 128;
165
2.98M
  unsigned char* ptr = lossless_cast<unsigned char*>(dst);
166
4.25M
  while (v >= B) {
167
1.27M
    *(ptr++) = (v & (B - 1)) | B;
168
1.27M
    v >>= 7;
169
1.27M
  }
170
2.98M
  *(ptr++) = static_cast<unsigned char>(v);
171
2.98M
  return lossless_cast<char*>(ptr);
172
2.98M
}
173
174
1.34M
inline void PutVarint64(std::string* dst, uint64_t v) {
175
1.34M
  char buf[kMaxVarint64Length];
176
1.34M
  char* ptr = EncodeVarint64(buf, v);
177
1.34M
  dst->append(buf, static_cast<size_t>(ptr - buf));
178
1.34M
}
179
180
7.18k
inline void PutVarsignedint64(std::string* dst, int64_t v) {
181
7.18k
  char buf[kMaxVarint64Length];
182
  // Using Zigzag format to convert signed to unsigned
183
7.18k
  char* ptr = EncodeVarint64(buf, i64ToZigzag(v));
184
7.18k
  dst->append(buf, static_cast<size_t>(ptr - buf));
185
7.18k
}
186
187
205k
inline void PutVarint64Varint64(std::string* dst, uint64_t v1, uint64_t v2) {
188
205k
  char buf[20];
189
205k
  char* ptr = EncodeVarint64(buf, v1);
190
205k
  ptr = EncodeVarint64(ptr, v2);
191
205k
  dst->append(buf, static_cast<size_t>(ptr - buf));
192
205k
}
193
194
1.20M
inline void PutVarint32Varint64(std::string* dst, uint32_t v1, uint64_t v2) {
195
1.20M
  char buf[15];
196
1.20M
  char* ptr = EncodeVarint32(buf, v1);
197
1.20M
  ptr = EncodeVarint64(ptr, v2);
198
1.20M
  dst->append(buf, static_cast<size_t>(ptr - buf));
199
1.20M
}
200
201
inline void PutVarint32Varint32Varint64(std::string* dst, uint32_t v1,
202
15.4k
                                        uint32_t v2, uint64_t v3) {
203
15.4k
  char buf[20];
204
15.4k
  char* ptr = EncodeVarint32(buf, v1);
205
15.4k
  ptr = EncodeVarint32(ptr, v2);
206
15.4k
  ptr = EncodeVarint64(ptr, v3);
207
15.4k
  dst->append(buf, static_cast<size_t>(ptr - buf));
208
15.4k
}
209
210
2.86M
inline void PutLengthPrefixedSlice(std::string* dst, const Slice& value) {
211
2.86M
  PutVarint32(dst, static_cast<uint32_t>(value.size()));
212
2.86M
  dst->append(value.data(), value.size());
213
2.86M
}
214
215
inline void PutLengthPrefixedSliceParts(std::string* dst, size_t total_bytes,
216
0
                                        const SliceParts& slice_parts) {
217
0
  for (int i = 0; i < slice_parts.num_parts; ++i) {
218
0
    total_bytes += slice_parts.parts[i].size();
219
0
  }
220
0
  PutVarint32(dst, static_cast<uint32_t>(total_bytes));
221
0
  for (int i = 0; i < slice_parts.num_parts; ++i) {
222
0
    dst->append(slice_parts.parts[i].data(), slice_parts.parts[i].size());
223
0
  }
224
0
}
225
226
inline void PutLengthPrefixedSliceParts(std::string* dst,
227
0
                                        const SliceParts& slice_parts) {
228
0
  PutLengthPrefixedSliceParts(dst, /*total_bytes=*/0, slice_parts);
229
0
}
230
231
inline void PutLengthPrefixedSlicePartsWithPadding(
232
0
    std::string* dst, const SliceParts& slice_parts, size_t pad_sz) {
233
0
  PutLengthPrefixedSliceParts(dst, /*total_bytes=*/pad_sz, slice_parts);
234
0
  dst->append(pad_sz, '\0');
235
0
}
236
237
3.12M
inline uint16_t VarintLength(uint64_t v) {
238
3.12M
  uint16_t len = 1;
239
3.43M
  while (v >= 128) {
240
314k
    v >>= 7;
241
314k
    len++;
242
314k
  }
243
3.12M
  return len;
244
3.12M
}
245
246
149k
inline bool GetFixed64(Slice* input, uint64_t* value) {
247
149k
  if (input->size() < sizeof(uint64_t)) {
248
0
    return false;
249
0
  }
250
149k
  *value = DecodeFixed64(input->data());
251
149k
  input->remove_prefix(sizeof(uint64_t));
252
149k
  return true;
253
149k
}
254
255
361k
inline bool GetFixed32(Slice* input, uint32_t* value) {
256
361k
  if (input->size() < sizeof(uint32_t)) {
257
0
    return false;
258
0
  }
259
361k
  *value = DecodeFixed32(input->data());
260
361k
  input->remove_prefix(sizeof(uint32_t));
261
361k
  return true;
262
361k
}
263
264
0
inline bool GetFixed16(Slice* input, uint16_t* value) {
265
0
  if (input->size() < sizeof(uint16_t)) {
266
0
    return false;
267
0
  }
268
0
  *value = DecodeFixed16(input->data());
269
0
  input->remove_prefix(sizeof(uint16_t));
270
0
  return true;
271
0
}
272
273
10.2M
inline bool GetVarint32(Slice* input, uint32_t* value) {
274
10.2M
  const char* p = input->data();
275
10.2M
  const char* limit = p + input->size();
276
10.2M
  const char* q = GetVarint32Ptr(p, limit, value);
277
10.2M
  if (q == nullptr) {
278
486k
    return false;
279
9.80M
  } else {
280
9.80M
    *input = Slice(q, static_cast<size_t>(limit - q));
281
9.80M
    return true;
282
9.80M
  }
283
10.2M
}
284
285
5.66M
inline bool GetVarint64(Slice* input, uint64_t* value) {
286
5.66M
  const char* p = input->data();
287
5.66M
  const char* limit = p + input->size();
288
5.66M
  const char* q = GetVarint64Ptr(p, limit, value);
289
5.66M
  if (q == nullptr) {
290
0
    return false;
291
5.66M
  } else {
292
5.66M
    *input = Slice(q, static_cast<size_t>(limit - q));
293
5.66M
    return true;
294
5.66M
  }
295
5.66M
}
296
297
0
inline bool GetVarsignedint64(Slice* input, int64_t* value) {
298
0
  const char* p = input->data();
299
0
  const char* limit = p + input->size();
300
0
  const char* q = GetVarsignedint64Ptr(p, limit, value);
301
0
  if (q == nullptr) {
302
0
    return false;
303
0
  } else {
304
0
    *input = Slice(q, static_cast<size_t>(limit - q));
305
0
    return true;
306
0
  }
307
0
}
308
309
5.77M
inline bool GetLengthPrefixedSlice(Slice* input, Slice* result) {
310
5.77M
  uint32_t len = 0;
311
5.77M
  if (GetVarint32(input, &len) && input->size() >= len) {
312
5.77M
    *result = Slice(input->data(), len);
313
5.77M
    input->remove_prefix(len);
314
5.77M
    return true;
315
5.77M
  } else {
316
0
    return false;
317
0
  }
318
5.77M
}
319
320
19.5M
inline Slice GetLengthPrefixedSlice(const char* data) {
321
19.5M
  uint32_t len = 0;
322
  // +5: we assume "data" is not corrupted
323
  // unsigned char is 7 bits, uint32_t is 32 bits, need 5 unsigned char
324
19.5M
  auto p = GetVarint32Ptr(data, data + 5 /* limit */, &len);
325
19.5M
  return Slice(p, len);
326
19.5M
}
327
328
0
inline Slice GetSliceUntil(Slice* slice, char delimiter) {
329
0
  uint32_t len = 0;
330
0
  for (len = 0; len < slice->size() && slice->data()[len] != delimiter; ++len) {
331
0
    // nothing
332
0
  }
333
0
334
0
  Slice ret(slice->data(), len);
335
0
  slice->remove_prefix(len + ((len < slice->size()) ? 1 : 0));
336
0
  return ret;
337
0
}
338
339
template <class T>
340
#ifdef ROCKSDB_UBSAN_RUN
341
#if defined(__clang__)
342
__attribute__((__no_sanitize__("alignment")))
343
#elif defined(__GNUC__)
344
__attribute__((__no_sanitize_undefined__))
345
#endif
346
#endif
347
7.00M
inline void PutUnaligned(T* memory, const T& value) {
348
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
349
  char* nonAlignedMemory = reinterpret_cast<char*>(memory);
350
  memcpy(nonAlignedMemory, reinterpret_cast<const char*>(&value), sizeof(T));
351
#else
352
7.00M
  *memory = value;
353
7.00M
#endif
354
7.00M
}
void rocksdb::PutUnaligned<long>(long*, long const&)
Line
Count
Source
347
131k
inline void PutUnaligned(T* memory, const T& value) {
348
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
349
  char* nonAlignedMemory = reinterpret_cast<char*>(memory);
350
  memcpy(nonAlignedMemory, reinterpret_cast<const char*>(&value), sizeof(T));
351
#else
352
131k
  *memory = value;
353
131k
#endif
354
131k
}
void rocksdb::PutUnaligned<unsigned long>(unsigned long*, unsigned long const&)
Line
Count
Source
347
6.87M
inline void PutUnaligned(T* memory, const T& value) {
348
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
349
  char* nonAlignedMemory = reinterpret_cast<char*>(memory);
350
  memcpy(nonAlignedMemory, reinterpret_cast<const char*>(&value), sizeof(T));
351
#else
352
6.87M
  *memory = value;
353
6.87M
#endif
354
6.87M
}
Unexecuted instantiation: void rocksdb::PutUnaligned<unsigned int>(unsigned int*, unsigned int const&)
355
356
template <class T>
357
#ifdef ROCKSDB_UBSAN_RUN
358
#if defined(__clang__)
359
__attribute__((__no_sanitize__("alignment")))
360
#elif defined(__GNUC__)
361
__attribute__((__no_sanitize_undefined__))
362
#endif
363
#endif
364
28.4M
inline void GetUnaligned(const T* memory, T* value) {
365
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
366
  char* nonAlignedMemory = reinterpret_cast<char*>(value);
367
  memcpy(nonAlignedMemory, reinterpret_cast<const char*>(memory), sizeof(T));
368
#else
369
28.4M
  *value = *memory;
370
28.4M
#endif
371
28.4M
}
void rocksdb::GetUnaligned<long>(long const*, long*)
Line
Count
Source
364
526k
inline void GetUnaligned(const T* memory, T* value) {
365
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
366
  char* nonAlignedMemory = reinterpret_cast<char*>(value);
367
  memcpy(nonAlignedMemory, reinterpret_cast<const char*>(memory), sizeof(T));
368
#else
369
526k
  *value = *memory;
370
526k
#endif
371
526k
}
void rocksdb::GetUnaligned<unsigned long>(unsigned long const*, unsigned long*)
Line
Count
Source
364
27.9M
inline void GetUnaligned(const T* memory, T* value) {
365
#if defined(PLATFORM_UNALIGNED_ACCESS_NOT_ALLOWED)
366
  char* nonAlignedMemory = reinterpret_cast<char*>(value);
367
  memcpy(nonAlignedMemory, reinterpret_cast<const char*>(memory), sizeof(T));
368
#else
369
27.9M
  *value = *memory;
370
27.9M
#endif
371
27.9M
}
Unexecuted instantiation: void rocksdb::GetUnaligned<unsigned int>(unsigned int const*, unsigned int*)
372
373
}  // namespace ROCKSDB_NAMESPACE