Skip to content

Commit 772919e

Browse files
committed
Use unique_ptr instead of new/delete
1 parent 95e6fc2 commit 772919e

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

benchmark/parsingcompetition.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#endif //__linux__
88
#endif // _MSC_VER
99

10+
#include <memory>
11+
1012
#include "benchmark.h"
1113

1214

@@ -225,7 +227,7 @@ int main(int argc, char *argv[]) {
225227

226228

227229

228-
jsmntok_t * tokens = new jsmntok_t[p.size()];
230+
auto * tokens = make_unique<jsmntok_t[](p.size());
229231
if(tokens == NULL) {
230232
printf("Failed to alloc memory for jsmn\n");
231233
} else {
@@ -234,9 +236,8 @@ int main(int argc, char *argv[]) {
234236
memcpy(buffer, p.data(), p.size());
235237
buffer[p.size()] = '\0';
236238
BEST_TIME("jsmn ",
237-
(jsmn_parse(&parser, buffer, p.size(), tokens, p.size()) > 0), true,
239+
(jsmn_parse(&parser, buffer, p.size(), tokens.get(), p.size()) > 0), true,
238240
jsmn_init(&parser), repeat, volume, !justdata);
239-
delete[] tokens;
240241
}
241242

242243
memcpy(buffer, p.data(), p.size());

tests/allparserscheckfile.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,18 +106,17 @@ int main(int argc, char *argv[]) {
106106
void *state;
107107
bool ultrajson_correct = ((UJDecode(buffer, p.size(), NULL, &state) == NULL) == false);
108108

109-
jsmntok_t * tokens = new jsmntok_t[p.size()];
109+
auto * tokens = make_unique<jsmntok_t[](p.size());
110110
bool jsmn_correct = false;
111-
if(tokens == NULL) {
111+
if(tokens == nullptr) {
112112
printf("Failed to alloc memory for jsmn\n");
113113
} else {
114114
jsmn_parser parser;
115115
jsmn_init(&parser);
116116
memcpy(buffer, p.data(), p.size());
117117
buffer[p.size()] = '\0';
118-
int r = jsmn_parse(&parser, buffer, p.size(), tokens, p.size());
119-
delete[] tokens;
120-
tokens = NULL;
118+
int r = jsmn_parse(&parser, buffer, p.size(), tokens.get(), p.size());
119+
tokens = nullptr;
121120
jsmn_correct = (r > 0);
122121
}
123122

0 commit comments

Comments
 (0)