Skip to content

Commit 2abf45f

Browse files
Aman Sharmafacebook-github-bot
authored andcommitted
Make ChainedByteRange a private subclass of ChainedByteRangeHead
Summary: We never instantiate a `ChainedByteRange` outside of the `ChainedByteRangeHead`, so I'm making it a private subclass. Reviewed By: hanidamlaj Differential Revision: D59402909 fbshipit-source-id: a819f3de5dcc68b370c46aa4e5fe3357f17b798f
1 parent 25b2e43 commit 2abf45f

File tree

4 files changed

+46
-53
lines changed

4 files changed

+46
-53
lines changed

quic/common/BufUtil.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ void BufWriter::insert(const ChainedByteRangeHead* data) {
175175
}
176176

177177
void BufWriter::insert(const ChainedByteRangeHead* data, size_t limit) {
178-
copy(data->getHead(), limit);
178+
copy(data, limit);
179179
}
180180

181181
void BufWriter::append(size_t len) {
@@ -205,13 +205,13 @@ void BufWriter::copy(const folly::IOBuf* data, size_t limit) {
205205
CHECK_GE(limit, totalInserted);
206206
}
207207

208-
void BufWriter::copy(const ChainedByteRange* data, size_t limit) {
208+
void BufWriter::copy(const ChainedByteRangeHead* data, size_t limit) {
209209
if (!limit) {
210210
return;
211211
}
212212
sizeCheck(limit);
213213
size_t totalInserted = 0;
214-
const ChainedByteRange* curBuf = data;
214+
const auto* curBuf = data->getHead();
215215
auto remaining = limit;
216216
do {
217217
auto lenToCopy = std::min(curBuf->length(), remaining);

quic/common/BufUtil.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ class BufWriter {
140140
}
141141

142142
void copy(const folly::IOBuf* data, size_t limit);
143-
void copy(const ChainedByteRange* data, size_t limit);
143+
void copy(const ChainedByteRangeHead* data, size_t limit);
144144

145145
private:
146146
folly::IOBuf& iobuf_;

quic/common/ChainedByteRange.h

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,6 @@
1111

1212
namespace quic {
1313

14-
/*
15-
* The ChainedByteRange depicts one block of contiguous
16-
* memory, and has a next_ pointer. It has APIs
17-
* that can be used to trim the start or end of this specific
18-
* contiguous memory block.
19-
*/
20-
class ChainedByteRange {
21-
public:
22-
ChainedByteRange() : next_(nullptr) {}
23-
24-
explicit ChainedByteRange(folly::ByteRange range)
25-
: range_(range), next_(nullptr) {}
26-
27-
/**
28-
* Returns the length only of this ChainedByteRange
29-
*/
30-
[[nodiscard]] size_t length() const {
31-
return range_.size();
32-
}
33-
34-
/**
35-
* Trim the start of this specific contiguous memory block
36-
*/
37-
void trimStart(size_t n) {
38-
n = std::min(n, range_.size());
39-
range_.advance(n);
40-
}
41-
42-
[[nodiscard]] folly::ByteRange getRange() const {
43-
return range_;
44-
}
45-
46-
[[nodiscard]] ChainedByteRange* getNext() const {
47-
return next_;
48-
}
49-
50-
private:
51-
folly::ByteRange range_;
52-
ChainedByteRange* next_{nullptr};
53-
friend class ChainedByteRangeHead;
54-
};
55-
5614
/*
5715
* The ChainedByteRangeHead depicts the head of a chain of ChainedByteRanges.
5816
* It caches the length of the total chain, which is useful in many cases
@@ -61,6 +19,48 @@ class ChainedByteRange {
6119
* with the splitAtMost and trimStartAtMost APIs.
6220
*/
6321
class ChainedByteRangeHead {
22+
private:
23+
/*
24+
* The ChainedByteRange depicts one block of contiguous
25+
* memory, and has a next_ pointer. It has APIs
26+
* that can be used to trim the start or end of this specific
27+
* contiguous memory block.
28+
*/
29+
class ChainedByteRange {
30+
public:
31+
ChainedByteRange() = default;
32+
33+
explicit ChainedByteRange(folly::ByteRange range) : range_(range) {}
34+
35+
/**
36+
* Returns the length only of this ChainedByteRange
37+
*/
38+
[[nodiscard]] size_t length() const {
39+
return range_.size();
40+
}
41+
42+
/**
43+
* Trim the start of this specific contiguous memory block
44+
*/
45+
void trimStart(size_t n) {
46+
n = std::min(n, range_.size());
47+
range_.advance(n);
48+
}
49+
50+
[[nodiscard]] folly::ByteRange getRange() const {
51+
return range_;
52+
}
53+
54+
[[nodiscard]] ChainedByteRange* getNext() const {
55+
return next_;
56+
}
57+
58+
private:
59+
folly::ByteRange range_;
60+
ChainedByteRange* next_{nullptr};
61+
friend class ChainedByteRangeHead;
62+
};
63+
6464
public:
6565
explicit ChainedByteRangeHead(const Buf& buf);
6666

quic/common/test/ChainedByteRangeTest.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,6 @@ TEST(ChainedByteRangeHead, FromIobufEmpty) {
225225
EXPECT_TRUE(chainedByteRangeHead.empty());
226226
}
227227

228-
TEST(ChainedByteRangeHead, TrimStart) {
229-
auto cbr = std::make_unique<ChainedByteRange>(
230-
folly::ByteRange(kHello->data(), kHello->length()));
231-
cbr->trimStart(3);
232-
EXPECT_EQ(cbr->getRange().toString(), "lo");
233-
}
234-
235228
TEST(ChainedByteRangeHead, SplitHeadFromChainOfOne) {
236229
ChainedByteRangeHead queue;
237230
queue.append(kHello);

0 commit comments

Comments
 (0)