Skip to content

Commit fabe18d

Browse files
author
MarcoFalke
committed
Use value_type in CDataStream where possible
Also, simplify unit tests with the CDataStream::str method.
1 parent 94db963 commit fabe18d

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/streams.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class CDataStream
226226
: nType{nTypeIn},
227227
nVersion{nVersionIn} {}
228228

229-
explicit CDataStream(Span<const uint8_t> sp, int nTypeIn, int nVersionIn)
229+
explicit CDataStream(Span<const value_type> sp, int nTypeIn, int nVersionIn)
230230
: vch(sp.data(), sp.data() + sp.size()),
231231
nType{nTypeIn},
232232
nVersion{nVersionIn} {}
@@ -254,17 +254,17 @@ class CDataStream
254254
iterator end() { return vch.end(); }
255255
size_type size() const { return vch.size() - nReadPos; }
256256
bool empty() const { return vch.size() == nReadPos; }
257-
void resize(size_type n, value_type c=0) { vch.resize(n + nReadPos, c); }
257+
void resize(size_type n, value_type c = value_type{}) { vch.resize(n + nReadPos, c); }
258258
void reserve(size_type n) { vch.reserve(n + nReadPos); }
259259
const_reference operator[](size_type pos) const { return vch[pos + nReadPos]; }
260260
reference operator[](size_type pos) { return vch[pos + nReadPos]; }
261261
void clear() { vch.clear(); nReadPos = 0; }
262-
iterator insert(iterator it, const uint8_t x) { return vch.insert(it, x); }
263-
void insert(iterator it, size_type n, const uint8_t x) { vch.insert(it, n, x); }
262+
iterator insert(iterator it, const value_type x) { return vch.insert(it, x); }
263+
void insert(iterator it, size_type n, const value_type x) { vch.insert(it, n, x); }
264264
value_type* data() { return vch.data() + nReadPos; }
265265
const value_type* data() const { return vch.data() + nReadPos; }
266266

267-
void insert(iterator it, std::vector<uint8_t>::const_iterator first, std::vector<uint8_t>::const_iterator last)
267+
void insert(iterator it, std::vector<value_type>::const_iterator first, std::vector<value_type>::const_iterator last)
268268
{
269269
if (last == first) return;
270270
assert(last - first > 0);
@@ -278,7 +278,7 @@ class CDataStream
278278
vch.insert(it, first, last);
279279
}
280280

281-
void insert(iterator it, const char* first, const char* last)
281+
void insert(iterator it, const value_type* first, const value_type* last)
282282
{
283283
if (last == first) return;
284284
assert(last - first > 0);

src/test/streams_tests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
172172
ds.Xor(key);
173173
BOOST_CHECK_EQUAL(
174174
std::string(expected_xor.begin(), expected_xor.end()),
175-
std::string(ds.begin(), ds.end()));
175+
ds.str());
176176

177177
in.push_back('\x0f');
178178
in.push_back('\xf0');
@@ -189,7 +189,7 @@ BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
189189
ds.Xor(key);
190190
BOOST_CHECK_EQUAL(
191191
std::string(expected_xor.begin(), expected_xor.end()),
192-
std::string(ds.begin(), ds.end()));
192+
ds.str());
193193

194194
// Multi character key
195195

@@ -210,7 +210,7 @@ BOOST_AUTO_TEST_CASE(streams_serializedata_xor)
210210
ds.Xor(key);
211211
BOOST_CHECK_EQUAL(
212212
std::string(expected_xor.begin(), expected_xor.end()),
213-
std::string(ds.begin(), ds.end()));
213+
ds.str());
214214
}
215215

216216
BOOST_AUTO_TEST_CASE(streams_buffered_file)

0 commit comments

Comments
 (0)