Skip to content

Commit 87acab0

Browse files
ostriMatjaž Ostroveršniklemire
authored
elimination of most of g++ -Weffc++ warnings (simdjson#764)
Co-authored-by: Matjaž Ostroveršnik <ostri@localhost.localdomain> Co-authored-by: Daniel Lemire <lemire@gmail.com>
1 parent f43459d commit 87acab0

File tree

13 files changed

+93
-49
lines changed

13 files changed

+93
-49
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,3 +218,7 @@ _deps
218218
# We check in a custom version of root Makefile that is not generated by CMake
219219
!/Makefile
220220

221+
singleheader/amalgamation_demo
222+
singleheader/amalgamation_demo.cpp
223+
singleheader/simdjson.cpp
224+
singleheader/simdjson.h

HACKING.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ simdjson's source structure, from the top level, looks like this:
2020
implementations).
2121
* simdjson.cpp: A "master source" that includes all implementation files from src/. This is
2222
equivalent to the distributed simdjson.cpp.
23-
* arm64/|fallback/|haswell/|westmere/: Architecture-specific implementations. All functions are
23+
* arm64/|fallback/|haswell/|westmere/: Architecture-specific implementations. All functions are
2424
Each architecture defines its own namespace, e.g. simdjson::haswell.
2525
* generic/: Generic implementations of the simdjson parser. These files may be included and
2626
compiled multiple times, from whichever architectures use them. They assume they are already
@@ -56,7 +56,7 @@ Other important files and directories:
5656
* **tools:** Source for executables that can be distributed with simdjson
5757

5858
> **Don't modify the files in singleheader/ directly; these are automatically generated.**
59-
>
59+
>
6060
> While we distribute those files on release, we *maintain* the files under include/ and src/.
6161
6262
While simdjson distributes just two files from the singleheader/ directory, we *maintain* the code in
@@ -157,6 +157,19 @@ make
157157
make test
158158
```
159159
160+
linux way:
161+
162+
```
163+
mkdir build # if necessary
164+
cd build
165+
cmake .. -DCMAKE_CXX_COMPILER=g++ -DCMAKE_CC_COMPILER=gcc # or
166+
cmake .. -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CC_COMPILER=clang
167+
make -j
168+
```
169+
170+
171+
172+
160173
### Usage (CMake on 64-bit Windows using Visual Studio)
161174
162175
We assume you have a common 64-bit Windows PC with at least Visual Studio 2017 and an x64 processor with AVX2 support (2013 Intel Haswell or later) or SSE 4.2 + CLMUL (2010 Westmere or later).
@@ -189,7 +202,7 @@ On Windows (64-bit):
189202
will build and install `simdjson` as a shared library.
190203
191204
```
192-
.\vcpkg.exe install simdjson:x64-windows-static
205+
.\vcpkg.exe install simdjson:x64-windows-static
193206
```
194207
195208
will build and install `simdjson` as a static library.

include/simdjson/document.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,9 @@ class array : protected internal::tape_ref {
124124
* Get the next value.
125125
*
126126
* Part of the std::iterator interface.
127+
*
127128
*/
128-
inline void operator++() noexcept;
129+
inline iterator& operator++() noexcept;
129130
/**
130131
* Check if these values come from the same place in the JSON.
131132
*
@@ -205,8 +206,9 @@ class object : protected internal::tape_ref {
205206
* Get the next key/value pair.
206207
*
207208
* Part of the std::iterator interface.
209+
*
208210
*/
209-
inline void operator++() noexcept;
211+
inline iterator& operator++() noexcept;
210212
/**
211213
* Check if these key value pairs come from the same place in the JSON.
212214
*
@@ -373,13 +375,13 @@ class document {
373375
bool dump_raw_tape(std::ostream &os) const noexcept;
374376

375377
/** @private Structural values. */
376-
std::unique_ptr<uint64_t[]> tape;
378+
std::unique_ptr<uint64_t[]> tape{};
377379

378380
/** @private String values.
379381
*
380382
* Should be at least byte_capacity.
381383
*/
382-
std::unique_ptr<uint8_t[]> string_buf;
384+
std::unique_ptr<uint8_t[]> string_buf{};
383385

384386
private:
385387
inline error_code allocate(size_t len) noexcept;
@@ -660,8 +662,7 @@ class parser {
660662
* to allocate an initial capacity, call allocate() after constructing the parser.
661663
* Defaults to SIMDJSON_MAXSIZE_BYTES (the largest single document simdjson can process).
662664
*/
663-
really_inline parser(size_t max_capacity = SIMDJSON_MAXSIZE_BYTES) noexcept;
664-
665+
really_inline explicit parser(size_t max_capacity = SIMDJSON_MAXSIZE_BYTES) noexcept;
665666
/**
666667
* Take another parser's buffers and state.
667668
*
@@ -811,7 +812,7 @@ class parser {
811812
* - CAPACITY if the parser does not have enough capacity and batch_size > max_capacity.
812813
* - other json errors if parsing fails.
813814
*/
814-
inline document_stream load_many(const std::string &path, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
815+
inline document_stream load_many(const std::string &path, size_t batch_size = DEFAULT_BATCH_SIZE) noexcept;
815816

816817
/**
817818
* Parse a buffer containing many JSON documents.
@@ -953,29 +954,29 @@ class parser {
953954
/** @private Number of structural indices passed from stage 1 to stage 2 */
954955
uint32_t n_structural_indexes{0};
955956
/** @private Structural indices passed from stage 1 to stage 2 */
956-
std::unique_ptr<uint32_t[]> structural_indexes;
957+
std::unique_ptr<uint32_t[]> structural_indexes{};
957958

958959
/** @private Tape location of each open { or [ */
959-
std::unique_ptr<scope_descriptor[]> containing_scope;
960+
std::unique_ptr<scope_descriptor[]> containing_scope{};
960961

961962
#ifdef SIMDJSON_USE_COMPUTED_GOTO
962963
/** @private Return address of each open { or [ */
963-
std::unique_ptr<void*[]> ret_address;
964+
std::unique_ptr<void*[]> ret_address{};
964965
#else
965966
/** @private Return address of each open { or [ */
966-
std::unique_ptr<char[]> ret_address;
967+
std::unique_ptr<char[]> ret_address{};
967968
#endif
968969

969970
/** @private Next write location in the string buf for stage 2 parsing */
970-
uint8_t *current_string_buf_loc;
971+
uint8_t *current_string_buf_loc{};
971972

972973
/** @private Use `if (parser.parse(...).error())` instead */
973974
bool valid{false};
974975
/** @private Use `parser.parse(...).error()` instead */
975976
error_code error{UNINITIALIZED};
976977

977978
/** @private Use `parser.parse(...).value()` instead */
978-
document doc;
979+
document doc{};
979980

980981
/** @private returns true if the document parsed was valid */
981982
[[deprecated("Use the result of parser.parse() instead")]]

include/simdjson/document_stream.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ class document_stream {
135135
error_code error{SUCCESS_AND_HAS_MORE};
136136
#ifdef SIMDJSON_THREADS_ENABLED
137137
error_code stage1_is_ok_thread{SUCCESS};
138-
std::thread stage_1_thread;
139-
dom::parser parser_thread;
138+
std::thread stage_1_thread{};
139+
dom::parser parser_thread{};
140140
#endif
141141
friend class dom::parser;
142142
}; // class document_stream

include/simdjson/implementation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ namespace simdjson {
1717
*/
1818
class implementation {
1919
public:
20+
2021
/**
2122
* The name of this implementation.
2223
*
@@ -131,6 +132,7 @@ class implementation {
131132
_required_instruction_sets(required_instruction_sets)
132133
{
133134
}
135+
virtual ~implementation()=default;
134136

135137
private:
136138
/**

include/simdjson/inline/document.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ inline error_code document::allocate(size_t capacity) noexcept {
213213

214214
// a pathological input like "[[[[..." would generate len tape elements, so
215215
// need a capacity of at least len + 1, but it is also possible to do
216-
// worse with "[7,7,7,7,6,7,7,7,6,7,7,6,[7,7,7,7,6,7,7,7,6,7,7,6,7,7,7,7,7,7,6"
216+
// worse with "[7,7,7,7,6,7,7,7,6,7,7,6,[7,7,7,7,6,7,7,7,6,7,7,6,7,7,7,7,7,7,6"
217217
//where len + 1 tape elements are
218218
// generated, see issue https://github.com/lemire/simdjson/issues/345
219219
size_t tape_capacity = ROUNDUP_N(capacity + 2, 64);
@@ -322,7 +322,9 @@ inline bool document::dump_raw_tape(std::ostream &os) const noexcept {
322322
// parser inline implementation
323323
//
324324
really_inline parser::parser(size_t max_capacity) noexcept
325-
: _max_capacity{max_capacity}, loaded_bytes(nullptr, &aligned_free_char) {}
325+
: _max_capacity{max_capacity},
326+
loaded_bytes(nullptr, &aligned_free_char)
327+
{}
326328
inline bool parser::is_valid() const noexcept { return valid; }
327329
inline int parser::get_error_code() const noexcept { return error; }
328330
inline std::string parser::get_error_message() const noexcept { return error_message(error); }
@@ -604,8 +606,9 @@ inline element array::iterator::operator*() const noexcept {
604606
inline bool array::iterator::operator!=(const array::iterator& other) const noexcept {
605607
return json_index != other.json_index;
606608
}
607-
inline void array::iterator::operator++() noexcept {
609+
inline array::iterator& array::iterator::operator++() noexcept {
608610
json_index = after_element();
611+
return *this;
609612
}
610613

611614
//
@@ -703,9 +706,10 @@ inline const key_value_pair object::iterator::operator*() const noexcept {
703706
inline bool object::iterator::operator!=(const object::iterator& other) const noexcept {
704707
return json_index != other.json_index;
705708
}
706-
inline void object::iterator::operator++() noexcept {
709+
inline object::iterator& object::iterator::operator++() noexcept {
707710
json_index++;
708711
json_index = after_element();
712+
return *this;
709713
}
710714
inline std::string_view object::iterator::key() const noexcept {
711715
size_t string_buf_index = size_t(tape_value());

include/simdjson/inline/document_stream.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static inline bool is_ascii(char c) {
8585
return ((unsigned char)c) <= 127;
8686
}
8787

88-
// if the string ends with UTF-8 values, backtrack
88+
// if the string ends with UTF-8 values, backtrack
8989
// up to the first ASCII character. May return 0.
9090
static inline size_t trimmed_length_safe_utf8(const char * c, size_t len) {
9191
while ((len > 0) and (not is_ascii(c[len - 1]))) {
@@ -100,14 +100,19 @@ static inline size_t trimmed_length_safe_utf8(const char * c, size_t len) {
100100

101101
namespace simdjson {
102102
namespace dom {
103-
104103
really_inline document_stream::document_stream(
105104
dom::parser &_parser,
106105
const uint8_t *buf,
107106
size_t len,
108107
size_t batch_size,
109108
error_code _error
110-
) noexcept : parser{_parser}, _buf{buf}, _len{len}, _batch_size(batch_size), error{_error} {
109+
) noexcept
110+
: parser{_parser},
111+
_buf{buf},
112+
_len{len},
113+
_batch_size(batch_size),
114+
error(_error)
115+
{
111116
if (!error) { error = json_parse(); }
112117
}
113118

include/simdjson/inline/parsedjson_iterator.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ bool dom::parser::Iterator::next() {
212212
current_type = next_type;
213213
return true;
214214
}
215-
216215
dom::parser::Iterator::Iterator(const dom::parser &pj) noexcept(false)
217-
: doc(pj.doc), depth(0), location(0), tape_length(0) {
216+
: doc(pj.doc)
217+
{
218218
#if SIMDJSON_EXCEPTIONS
219219
if (!pj.valid) { throw simdjson_error(pj.error); }
220220
#else
@@ -239,12 +239,17 @@ dom::parser::Iterator::Iterator(const dom::parser &pj) noexcept(false)
239239
depth_index[depth].scope_type = current_type;
240240
}
241241
}
242-
243242
dom::parser::Iterator::Iterator(
244243
const dom::parser::Iterator &o) noexcept
245-
: doc(o.doc), max_depth(o.depth), depth(o.depth), location(o.location),
246-
tape_length(o.tape_length), current_type(o.current_type),
247-
current_val(o.current_val) {
244+
: doc(o.doc),
245+
max_depth(o.depth),
246+
depth(o.depth),
247+
location(o.location),
248+
tape_length(o.tape_length),
249+
current_type(o.current_type),
250+
current_val(o.current_val),
251+
depth_index()
252+
{
248253
depth_index = new scopeindex_t[max_depth+1];
249254
memcpy(depth_index, o.depth_index, (depth + 1) * sizeof(depth_index[0]));
250255
}

include/simdjson/parsedjson_iterator.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class [[deprecated("Use the new DOM navigation API instead (see doc/usage.md)")]
2222
inline Iterator(const Iterator &o) noexcept;
2323
inline ~Iterator() noexcept;
2424

25+
inline Iterator& operator=(const Iterator&) = delete;
26+
2527
inline bool is_ok() const;
2628

2729
// useful for debugging purposes
@@ -253,13 +255,13 @@ class [[deprecated("Use the new DOM navigation API instead (see doc/usage.md)")]
253255

254256
private:
255257
const document &doc;
256-
size_t max_depth;
257-
size_t depth;
258-
size_t location; // our current location on a tape
259-
size_t tape_length;
260-
uint8_t current_type;
261-
uint64_t current_val;
262-
scopeindex_t *depth_index;
258+
size_t max_depth{};
259+
size_t depth{};
260+
size_t location{}; // our current location on a tape
261+
size_t tape_length{};
262+
uint8_t current_type{};
263+
uint64_t current_val{};
264+
scopeindex_t *depth_index{};
263265
};
264266

265267
} // namespace simdjson

src/generic/json_minifier.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ class json_minifier {
1111
static error_code minify(const uint8_t *buf, size_t len, uint8_t *dst, size_t &dst_len) noexcept;
1212

1313
private:
14-
really_inline json_minifier(uint8_t *_dst) : dst{_dst} {}
14+
really_inline json_minifier(uint8_t *_dst)
15+
: dst{_dst}
16+
{}
1517
template<size_t STEP_SIZE>
1618
really_inline void step(const uint8_t *block_buf, buf_block_reader<STEP_SIZE> &reader) noexcept;
1719
really_inline void next(simd::simd8x64<uint8_t> in, json_block block);
1820
really_inline error_code finish(uint8_t *dst_start, size_t &dst_len);
19-
json_scanner scanner;
21+
json_scanner scanner{};
2022
uint8_t *dst;
2123
};
2224

@@ -70,4 +72,4 @@ error_code json_minifier::minify(const uint8_t *buf, size_t len, uint8_t *dst, s
7072
return minifier.finish(dst, dst_len);
7173
}
7274

73-
} // namespace stage1
75+
} // namespace stage1

0 commit comments

Comments
 (0)