• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

arangodb / velocypack / 3998645281

pending completion
3998645281

Pull #148

github

GitHub
Merge b1e3c924b into 5a28b6413
Pull Request #148: use separate namespace for xxh functions

0 of 5107 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/SharedSlice.cpp
1
////////////////////////////////////////////////////////////////////////////////
2
/// DISCLAIMER
3
///
4
/// Copyright 2014-2020 ArangoDB GmbH, Cologne, Germany
5
/// Copyright 2004-2014 triAGENS GmbH, Cologne, Germany
6
///
7
/// Licensed under the Apache License, Version 2.0 (the "License");
8
/// you may not use this file except in compliance with the License.
9
/// You may obtain a copy of the License at
10
///
11
///     http://www.apache.org/licenses/LICENSE-2.0
12
///
13
/// Unless required by applicable law or agreed to in writing, software
14
/// distributed under the License is distributed on an "AS IS" BASIS,
15
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
/// See the License for the specific language governing permissions and
17
/// limitations under the License.
18
///
19
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
20
///
21
/// @author Tobias Gödderz
22
////////////////////////////////////////////////////////////////////////////////
23

24
#include <velocypack/SharedSlice.h>
25

26
using namespace arangodb;
27
using namespace arangodb::velocypack;
28

29
namespace {
30
std::shared_ptr<uint8_t const> const staticSharedNoneBuffer{
31
    Slice::noneSliceData, [](auto) { /* don't delete the pointer */ }};
×
32
}
33

34
void SharedSlice::nullToNone() noexcept {
×
35
  if (VELOCYPACK_UNLIKELY(_start == nullptr)) {
×
36
    _start = staticSharedNoneBuffer;
×
37
  }
38
}
×
39

40
std::shared_ptr<uint8_t const> SharedSlice::copyBuffer(
×
41
    Buffer<uint8_t> const& buffer) {
42
  // template<class T> shared_ptr<T> make_shared( std::size_t N );
43
  // with T is U[] is only available since C++20 :(
44
  auto newBuffer = std::shared_ptr<uint8_t>(new uint8_t[buffer.byteSize()],
×
45
                                            [](uint8_t* ptr) { delete[] ptr; });
×
46
  memcpy(newBuffer.get(), buffer.data(), checkOverflow(buffer.byteSize()));
×
47
  return newBuffer;
×
48
}
49

50
std::shared_ptr<uint8_t const> SharedSlice::stealBuffer(
×
51
    Buffer<uint8_t>&& buffer) {
52
  // If the buffer doesn't use memory on the heap, we have to copy it.
53
  if (buffer.usesLocalMemory()) {
×
54
    return copyBuffer(buffer);
×
55
  }
56
  // Buffer uses velocypack_malloc/velocypack_free for memory management
57
  return std::shared_ptr<uint8_t const>(
58
      buffer.steal(), [](auto ptr) { return velocypack_free(ptr); });
×
59
}
60

61
Slice SharedSlice::slice() const noexcept { return Slice(_start.get()); }
×
62

63
SharedSlice::SharedSlice(std::shared_ptr<uint8_t const>&& data) noexcept
×
64
    : _start(std::move(data)) {
×
65
  nullToNone();
×
66
}
×
67

68
SharedSlice::SharedSlice(std::shared_ptr<uint8_t const> const& data) noexcept
×
69
    : _start(data) {
×
70
  nullToNone();
×
71
}
×
72

73
SharedSlice::SharedSlice(Buffer<uint8_t>&& buffer) noexcept
×
74
    : _start(stealBuffer(std::move(buffer))) {
×
75
  nullToNone();
×
76
}
×
77

78
SharedSlice::SharedSlice(Buffer<uint8_t> const& buffer) noexcept
×
79
    : _start(copyBuffer(buffer)) {
×
80
  nullToNone();
×
81
}
×
82

83
SharedSlice::SharedSlice(SharedSlice&& sharedPtr, Slice slice) noexcept
×
84
    : _start(std::move(sharedPtr._start), slice.start()) {
×
85
  sharedPtr._start = staticSharedNoneBuffer;
×
86
  nullToNone();
×
87
}
×
88

89
SharedSlice::SharedSlice(SharedSlice const& sharedPtr, Slice slice) noexcept
×
90
    : _start(sharedPtr._start, slice.start()) {
×
91
  nullToNone();
×
92
}
×
93

94
SharedSlice::SharedSlice() noexcept : _start(staticSharedNoneBuffer) {}
×
95

96
SharedSlice SharedSlice::value() const noexcept {
×
97
  return alias(slice().value());
×
98
}
99

100
uint64_t SharedSlice::getFirstTag() const { return slice().getFirstTag(); }
×
101

102
std::vector<uint64_t> SharedSlice::getTags() const { return slice().getTags(); }
×
103

104
bool SharedSlice::hasTag(uint64_t tagId) const { return slice().hasTag(tagId); }
×
105

106
std::shared_ptr<uint8_t const> SharedSlice::valueStart() const noexcept {
×
107
  return aliasPtr(slice().valueStart());
×
108
}
109

110
std::shared_ptr<uint8_t const> SharedSlice::start() const noexcept {
×
111
  return aliasPtr(slice().start());
×
112
}
113

114
uint8_t SharedSlice::head() const noexcept { return slice().head(); }
×
115

116
std::shared_ptr<uint8_t const> SharedSlice::begin() const noexcept {
×
117
  return aliasPtr(slice().begin());
×
118
}
119

120
std::shared_ptr<uint8_t const> SharedSlice::end() const {
×
121
  return aliasPtr(slice().end());
×
122
}
123

124
ValueType SharedSlice::type() const noexcept { return slice().type(); }
×
125

126
char const* SharedSlice::typeName() const { return slice().typeName(); }
×
127

128
uint64_t SharedSlice::volatileHash() const { return slice().volatileHash(); }
×
129

130
uint64_t SharedSlice::hash(uint64_t seed) const { return slice().hash(seed); }
×
131

132
uint32_t SharedSlice::hash32(uint32_t seed) const {
×
133
  return slice().hash32(seed);
×
134
}
135

136
uint64_t SharedSlice::hashSlow(uint64_t seed) const {
×
137
  return slice().hashSlow(seed);
×
138
}
139

140
uint64_t SharedSlice::normalizedHash(uint64_t seed) const {
×
141
  return slice().normalizedHash(seed);
×
142
}
143

144
uint32_t SharedSlice::normalizedHash32(uint32_t seed) const {
×
145
  return slice().normalizedHash32(seed);
×
146
}
147

148
uint64_t SharedSlice::hashString(uint64_t seed) const noexcept {
×
149
  return slice().hashString(seed);
×
150
}
151

152
uint32_t SharedSlice::hashString32(uint32_t seed) const noexcept {
×
153
  return slice().hashString32(seed);
×
154
}
155

156
bool SharedSlice::isType(ValueType t) const { return slice().isType(t); }
×
157

158
bool SharedSlice::isNone() const noexcept { return slice().isNone(); }
×
159

160
bool SharedSlice::isIllegal() const noexcept { return slice().isIllegal(); }
×
161

162
bool SharedSlice::isNull() const noexcept { return slice().isNull(); }
×
163

164
bool SharedSlice::isBool() const noexcept { return slice().isBool(); }
×
165

166
bool SharedSlice::isBoolean() const noexcept { return slice().isBoolean(); }
×
167

168
bool SharedSlice::isTrue() const noexcept { return slice().isTrue(); }
×
169

170
bool SharedSlice::isFalse() const noexcept { return slice().isFalse(); }
×
171

172
bool SharedSlice::isArray() const noexcept { return slice().isArray(); }
×
173

174
bool SharedSlice::isObject() const noexcept { return slice().isObject(); }
×
175

176
bool SharedSlice::isDouble() const noexcept { return slice().isDouble(); }
×
177

178
bool SharedSlice::isUTCDate() const noexcept { return slice().isUTCDate(); }
×
179

180
bool SharedSlice::isExternal() const noexcept { return slice().isExternal(); }
×
181

182
bool SharedSlice::isMinKey() const noexcept { return slice().isMinKey(); }
×
183

184
bool SharedSlice::isMaxKey() const noexcept { return slice().isMaxKey(); }
×
185

186
bool SharedSlice::isInt() const noexcept { return slice().isInt(); }
×
187

188
bool SharedSlice::isUInt() const noexcept { return slice().isUInt(); }
×
189

190
bool SharedSlice::isSmallInt() const noexcept { return slice().isSmallInt(); }
×
191

192
bool SharedSlice::isString() const noexcept { return slice().isString(); }
×
193

194
bool SharedSlice::isBinary() const noexcept { return slice().isBinary(); }
×
195

196
bool SharedSlice::isBCD() const noexcept { return slice().isBCD(); }
×
197

198
bool SharedSlice::isCustom() const noexcept { return slice().isCustom(); }
×
199

200
bool SharedSlice::isTagged() const noexcept { return slice().isTagged(); }
×
201

202
bool SharedSlice::isInteger() const noexcept { return slice().isInteger(); }
×
203

204
bool SharedSlice::isNumber() const noexcept { return slice().isNumber(); }
×
205

206
bool SharedSlice::isSorted() const noexcept { return slice().isSorted(); }
×
207

208
bool SharedSlice::getBool() const { return slice().getBool(); }
×
209

210
bool SharedSlice::getBoolean() const { return slice().getBoolean(); }
×
211

212
double SharedSlice::getDouble() const { return slice().getDouble(); }
×
213

214
SharedSlice SharedSlice::at(ValueLength index) const {
×
215
  return alias(slice().at(index));
×
216
}
217

218
SharedSlice SharedSlice::operator[](ValueLength index) const {
×
219
  return alias(slice().operator[](index));
×
220
}
221

222
ValueLength SharedSlice::length() const { return slice().length(); }
×
223

224
SharedSlice SharedSlice::keyAt(ValueLength index, bool translate) const {
×
225
  return alias(slice().keyAt(index, translate));
×
226
}
227

228
SharedSlice SharedSlice::valueAt(ValueLength index) const {
×
229
  return alias(slice().valueAt(index));
×
230
}
231

232
SharedSlice SharedSlice::getNthValue(ValueLength index) const {
×
233
  return alias(slice().getNthValue(index));
×
234
}
235

236
SharedSlice SharedSlice::get(std::string_view attribute) const {
×
237
  return alias(slice().get(attribute));
×
238
}
239

240
SharedSlice SharedSlice::get(char const* attribute, std::size_t length) const {
×
241
  return alias(slice().get(std::string_view(attribute, length)));
×
242
}
243

244
SharedSlice SharedSlice::operator[](std::string_view attribute) const {
×
245
  return alias(slice().operator[](attribute));
×
246
}
247

248
bool SharedSlice::hasKey(std::string_view attribute) const {
×
249
  return slice().hasKey(attribute);
×
250
}
251

252
bool SharedSlice::hasKey(char const* attribute, std::size_t length) const {
×
253
  return slice().hasKey(std::string_view(attribute, length));
×
254
}
255

256
bool SharedSlice::hasKey(std::vector<std::string> const& attributes) const {
×
257
  return slice().hasKey(attributes);
×
258
}
259

260
std::shared_ptr<char const> SharedSlice::getExternal() const {
×
261
  return aliasPtr(slice().getExternal());
×
262
}
263

264
SharedSlice SharedSlice::resolveExternal() const {
×
265
  return alias(slice().resolveExternal());
×
266
}
267

268
SharedSlice SharedSlice::resolveExternals() const {
×
269
  return alias(slice().resolveExternals());
×
270
}
271

272
bool SharedSlice::isEmptyArray() const { return slice().isEmptyArray(); }
×
273

274
bool SharedSlice::isEmptyObject() const { return slice().isEmptyObject(); }
×
275

276
SharedSlice SharedSlice::translate() const {
×
277
  return alias(slice().translate());
×
278
}
279

280
int64_t SharedSlice::getInt() const { return slice().getInt(); }
×
281

282
uint64_t SharedSlice::getUInt() const { return slice().getUInt(); }
×
283

284
int64_t SharedSlice::getSmallInt() const { return slice().getSmallInt(); }
×
285

286
int64_t SharedSlice::getUTCDate() const { return slice().getUTCDate(); }
×
287

288
std::shared_ptr<char const> SharedSlice::getString(ValueLength& length) const {
×
289
  return aliasPtr(slice().getString(length));
×
290
}
291

292
std::shared_ptr<char const> SharedSlice::getStringUnchecked(
×
293
    ValueLength& length) const noexcept {
294
  return aliasPtr(slice().getStringUnchecked(length));
×
295
}
296

297
ValueLength SharedSlice::getStringLength() const {
×
298
  return slice().getStringLength();
×
299
}
300

301
std::string SharedSlice::copyString() const { return slice().copyString(); }
×
302

303
[[deprecated("use stringView")]] StringRef SharedSlice::stringRef() const {
×
304
  return slice().stringRef();
×
305
}
306

307
std::string_view SharedSlice::stringView() const {
×
308
  return slice().stringView();
×
309
}
310

311
std::shared_ptr<uint8_t const> SharedSlice::getBinary(
×
312
    ValueLength& length) const {
313
  return aliasPtr(slice().getBinary(length));
×
314
}
315

316
ValueLength SharedSlice::getBinaryLength() const {
×
317
  return slice().getBinaryLength();
×
318
}
319

320
std::vector<uint8_t> SharedSlice::copyBinary() const {
×
321
  return slice().copyBinary();
×
322
}
323

324
ValueLength SharedSlice::byteSize() const { return slice().byteSize(); }
×
325

326
ValueLength SharedSlice::valueByteSize() const {
×
327
  return slice().valueByteSize();
×
328
}
329

330
ValueLength SharedSlice::findDataOffset(uint8_t head) const noexcept {
×
331
  return slice().findDataOffset(head);
×
332
}
333

334
ValueLength SharedSlice::getNthOffset(ValueLength index) const {
×
335
  return slice().getNthOffset(index);
×
336
}
337

338
SharedSlice SharedSlice::makeKey() const { return alias(slice().makeKey()); }
×
339

340
int SharedSlice::compareString(std::string_view value) const {
×
341
  return slice().compareString(value);
×
342
}
343

344
int SharedSlice::compareString(char const* value, std::size_t length) const {
×
345
  return slice().compareString(std::string_view(value, length));
×
346
}
347

348
int SharedSlice::compareStringUnchecked(std::string_view value) const noexcept {
×
349
  return slice().compareStringUnchecked(value);
×
350
}
351

352
int SharedSlice::compareStringUnchecked(char const* value,
×
353
                                        std::size_t length) const noexcept {
354
  return slice().compareStringUnchecked(std::string_view(value, length));
×
355
}
356

357
bool SharedSlice::isEqualString(std::string_view attribute) const {
×
358
  return slice().isEqualString(attribute);
×
359
}
360

361
bool SharedSlice::isEqualStringUnchecked(
×
362
    std::string_view attribute) const noexcept {
363
  return slice().isEqualStringUnchecked(attribute);
×
364
}
365

366
bool SharedSlice::binaryEquals(Slice other) const {
×
367
  return slice().binaryEquals(other);
×
368
}
369

370
bool SharedSlice::binaryEquals(SharedSlice const& other) const {
×
371
  return slice().binaryEquals(other.slice());
×
372
}
373

374
std::string SharedSlice::toHex() const { return slice().toHex(); }
×
375

376
std::string SharedSlice::toJson(Options const* options) const {
×
377
  return slice().toJson(options);
×
378
}
379

380
std::string SharedSlice::toString(Options const* options) const {
×
381
  return slice().toString(options);
×
382
}
383

384
std::string SharedSlice::hexType() const { return slice().hexType(); }
×
385

386
int64_t SharedSlice::getIntUnchecked() const noexcept {
×
387
  return slice().getIntUnchecked();
×
388
}
389

390
uint64_t SharedSlice::getUIntUnchecked() const noexcept {
×
391
  return slice().getUIntUnchecked();
×
392
}
393

394
int64_t SharedSlice::getSmallIntUnchecked() const noexcept {
×
395
  return slice().getSmallIntUnchecked();
×
396
}
397

398
std::shared_ptr<uint8_t const> SharedSlice::getBCD(
×
399
    int8_t& sign, int32_t& exponent, ValueLength& mantissaLength) const {
400
  return aliasPtr(slice().getBCD(sign, exponent, mantissaLength));
×
401
}
402

403
SharedSlice SharedSlice::alias(Slice slice) const noexcept {
×
404
  return SharedSlice(*this, slice);
×
405
}
406

407
SharedSlice::SharedSlice(SharedSlice&& other) noexcept {
×
408
  _start = std::move(other._start);
×
409
  // Set other to point to None
410
  other._start = staticSharedNoneBuffer;
×
411
}
×
412

413
SharedSlice& SharedSlice::operator=(SharedSlice&& other) noexcept {
×
414
  _start = std::move(other._start);
×
415
  // Set other to point to None
416
  other._start = staticSharedNoneBuffer;
×
417
  return *this;
×
418
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc