Coverage Report

Created: 2026-05-19 06:24

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/duckdb/third_party/snappy/snappy-sinksource.cc
Line
Count
Source
1
// Copyright 2011 Google Inc. All Rights Reserved.
2
//
3
// Redistribution and use in source and binary forms, with or without
4
// modification, are permitted provided that the following conditions are
5
// met:
6
//
7
//     * Redistributions of source code must retain the above copyright
8
// notice, this list of conditions and the following disclaimer.
9
//     * Redistributions in binary form must reproduce the above
10
// copyright notice, this list of conditions and the following disclaimer
11
// in the documentation and/or other materials provided with the
12
// distribution.
13
//     * Neither the name of Google Inc. nor the names of its
14
// contributors may be used to endorse or promote products derived from
15
// this software without specific prior written permission.
16
//
17
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29
#include "snappy_version.hpp"
30
31
#if SNAPPY_NEW_VERSION
32
33
#include <stddef.h>
34
#include <cstring>
35
36
#include "snappy-sinksource.h"
37
38
namespace duckdb_snappy {
39
40
0
Source::~Source() = default;
41
42
0
Sink::~Sink() = default;
43
44
0
char* Sink::GetAppendBuffer(size_t length, char* scratch) {
45
  // TODO: Switch to [[maybe_unused]] when we can assume C++17.
46
0
  (void)length;
47
48
0
  return scratch;
49
0
}
50
51
char* Sink::GetAppendBufferVariable(
52
      size_t min_size, size_t desired_size_hint, char* scratch,
53
0
      size_t scratch_size, size_t* allocated_size) {
54
  // TODO: Switch to [[maybe_unused]] when we can assume C++17.
55
0
  (void)min_size;
56
0
  (void)desired_size_hint;
57
58
0
  *allocated_size = scratch_size;
59
0
  return scratch;
60
0
}
61
62
void Sink::AppendAndTakeOwnership(
63
    char* bytes, size_t n,
64
    void (*deleter)(void*, const char*, size_t),
65
0
    void *deleter_arg) {
66
0
  Append(bytes, n);
67
0
  (*deleter)(deleter_arg, bytes, n);
68
0
}
69
70
ByteArraySource::~ByteArraySource() = default;
71
72
0
size_t ByteArraySource::Available() const { return left_; }
73
74
0
const char* ByteArraySource::Peek(size_t* len) {
75
0
  *len = left_;
76
0
  return ptr_;
77
0
}
78
79
0
void ByteArraySource::Skip(size_t n) {
80
0
  left_ -= n;
81
0
  ptr_ += n;
82
0
}
83
84
UncheckedByteArraySink::~UncheckedByteArraySink() { }
85
86
0
void UncheckedByteArraySink::Append(const char* data, size_t n) {
87
  // Do no copying if the caller filled in the result of GetAppendBuffer()
88
0
  if (data != dest_) {
89
0
    std::memcpy(dest_, data, n);
90
0
  }
91
0
  dest_ += n;
92
0
}
93
94
0
char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) {
95
  // TODO: Switch to [[maybe_unused]] when we can assume C++17.
96
0
  (void)len;
97
0
  (void)scratch;
98
99
0
  return dest_;
100
0
}
101
102
void UncheckedByteArraySink::AppendAndTakeOwnership(
103
    char* bytes, size_t n,
104
    void (*deleter)(void*, const char*, size_t),
105
0
    void *deleter_arg) {
106
0
  if (bytes != dest_) {
107
0
    std::memcpy(dest_, bytes, n);
108
0
    (*deleter)(deleter_arg, bytes, n);
109
0
  }
110
0
  dest_ += n;
111
0
}
112
113
char* UncheckedByteArraySink::GetAppendBufferVariable(
114
      size_t min_size, size_t desired_size_hint, char* scratch,
115
0
      size_t scratch_size, size_t* allocated_size) {
116
  // TODO: Switch to [[maybe_unused]] when we can assume C++17.
117
0
  (void)min_size;
118
0
  (void)scratch;
119
0
  (void)scratch_size;
120
121
0
  *allocated_size = desired_size_hint;
122
0
  return dest_;
123
0
}
124
125
}  // namespace duckdb_snappy
126
127
#else // #if SNAPPY_NEW_VERSION
128
129
#include <string.h>
130
131
#include "snappy-sinksource.h"
132
133
namespace duckdb_snappy {
134
135
Source::~Source() { }
136
137
Sink::~Sink() { }
138
139
char* Sink::GetAppendBuffer(size_t length, char* scratch) {
140
  return scratch;
141
}
142
143
char* Sink::GetAppendBufferVariable(
144
    size_t min_size, size_t desired_size_hint, char* scratch,
145
    size_t scratch_size, size_t* allocated_size) {
146
  *allocated_size = scratch_size;
147
  return scratch;
148
}
149
150
void Sink::AppendAndTakeOwnership(
151
  char* bytes, size_t n,
152
  void (*deleter)(void*, const char*, size_t),
153
  void *deleter_arg) {
154
  Append(bytes, n);
155
  (*deleter)(deleter_arg, bytes, n);
156
}
157
158
ByteArraySource::~ByteArraySource() { }
159
160
size_t ByteArraySource::Available() const { return left_; }
161
162
const char* ByteArraySource::Peek(size_t* len) {
163
  *len = left_;
164
  return ptr_;
165
}
166
167
void ByteArraySource::Skip(size_t n) {
168
  left_ -= n;
169
  ptr_ += n;
170
}
171
172
UncheckedByteArraySink::~UncheckedByteArraySink() { }
173
174
void UncheckedByteArraySink::Append(const char* data, size_t n) {
175
  // Do no copying if the caller filled in the result of GetAppendBuffer()
176
  if (data != dest_) {
177
    memcpy(dest_, data, n);
178
  }
179
  dest_ += n;
180
}
181
182
char* UncheckedByteArraySink::GetAppendBuffer(size_t len, char* scratch) {
183
  return dest_;
184
}
185
186
void UncheckedByteArraySink::AppendAndTakeOwnership(
187
  char* data, size_t n,
188
  void (*deleter)(void*, const char*, size_t),
189
  void *deleter_arg) {
190
  if (data != dest_) {
191
    memcpy(dest_, data, n);
192
    (*deleter)(deleter_arg, data, n);
193
  }
194
  dest_ += n;
195
}
196
197
char* UncheckedByteArraySink::GetAppendBufferVariable(
198
    size_t min_size, size_t desired_size_hint, char* scratch,
199
    size_t scratch_size, size_t* allocated_size) {
200
  *allocated_size = desired_size_hint;
201
  return dest_;
202
}
203
204
}  // namespace duckdb_snappy
205
206
#endif  // #if SNAPPY_NEW_VERSION # else