Use unique_ptr instead of new/delete

This commit is contained in:
Kai Wolf 2019-02-25 21:03:20 +01:00
parent 95e6fc2844
commit 772919ef11
2 changed files with 8 additions and 8 deletions

View File

@ -7,6 +7,8 @@
#endif //__linux__
#endif // _MSC_VER
#include <memory>
#include "benchmark.h"
@ -225,7 +227,7 @@ int main(int argc, char *argv[]) {
jsmntok_t * tokens = new jsmntok_t[p.size()];
auto * tokens = make_unique<jsmntok_t[](p.size());
if(tokens == NULL) {
printf("Failed to alloc memory for jsmn\n");
} else {
@ -234,9 +236,8 @@ int main(int argc, char *argv[]) {
memcpy(buffer, p.data(), p.size());
buffer[p.size()] = '\0';
BEST_TIME("jsmn ",
(jsmn_parse(&parser, buffer, p.size(), tokens, p.size()) > 0), true,
(jsmn_parse(&parser, buffer, p.size(), tokens.get(), p.size()) > 0), true,
jsmn_init(&parser), repeat, volume, !justdata);
delete[] tokens;
}
memcpy(buffer, p.data(), p.size());

View File

@ -106,18 +106,17 @@ int main(int argc, char *argv[]) {
void *state;
bool ultrajson_correct = ((UJDecode(buffer, p.size(), NULL, &state) == NULL) == false);
jsmntok_t * tokens = new jsmntok_t[p.size()];
auto * tokens = make_unique<jsmntok_t[](p.size());
bool jsmn_correct = false;
if(tokens == NULL) {
if(tokens == nullptr) {
printf("Failed to alloc memory for jsmn\n");
} else {
jsmn_parser parser;
jsmn_init(&parser);
memcpy(buffer, p.data(), p.size());
buffer[p.size()] = '\0';
int r = jsmn_parse(&parser, buffer, p.size(), tokens, p.size());
delete[] tokens;
tokens = NULL;
int r = jsmn_parse(&parser, buffer, p.size(), tokens.get(), p.size());
tokens = nullptr;
jsmn_correct = (r > 0);
}