Skip to content

Commit e570733

Browse files
committed
Some refactoring.
1 parent 12b5185 commit e570733

30 files changed

+121
-113
lines changed

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ endif
1919

2020
EXECUTABLES=parse jsoncheck numberparsingcheck stringparsingcheck minifiercompetition parsingcompetition minify allparserscheckfile
2121

22-
HEADERS= include/jsonparser/simdutf8check.h include/jsonparser/stringparsing.h include/jsonparser/numberparsing.h include/jsonparser/jsonparser.h include/jsonparser/common_defs.h include/jsonparser/jsonioutil.h benchmark/benchmark.h benchmark/linux/linux-perf-events.h include/jsonparser/simdjson_internal.h include/jsonparser/stage1_find_marks.h include/jsonparser/stage2_flatten.h include/jsonparser/stage34_unified.h include/jsonparser/jsoncharutils.h
22+
HEADERS= include/simdjson/simdutf8check.h include/simdjson/stringparsing.h include/simdjson/numberparsing.h include/simdjson/jsonparser.h include/simdjson/common_defs.h include/simdjson/jsonioutil.h benchmark/benchmark.h benchmark/linux/linux-perf-events.h include/simdjson/parsedjson.h include/simdjson/stage1_find_marks.h include/simdjson/stage2_flatten.h include/simdjson/stage34_unified.h include/simdjson/jsoncharutils.h include/simdjson/jsonformatutils.h
2323
LIBFILES=src/jsonioutil.cpp src/jsonparser.cpp src/stage1_find_marks.cpp src/stage2_flatten.cpp src/stage34_unified.cpp
24-
MINIFIERHEADERS=include/jsonparser/jsonminifier.h include/jsonparser/simdprune_tables.h
24+
MINIFIERHEADERS=include/simdjson/jsonminifier.h include/simdjson/simdprune_tables.h
2525
MINIFIERLIBFILES=src/jsonminifier.cpp
2626

2727

@@ -100,6 +100,10 @@ allparserscheckfile: tests/allparserscheckfile.cpp $(HEADERS) $(LIBFILES) $(OBJE
100100
parsehisto: benchmark/parse.cpp $(HEADERS) $(LIBFILES)
101101
$(CXX) $(CXXFLAGS) -o parsehisto benchmark/parse.cpp $(LIBFILES) $(LIBFLAGS) -DBUILDHISTOGRAM
102102

103+
cppcheck:
104+
cppcheck --enable=all src/*.cpp benchmarks/*.cpp tests/*.cpp -Iinclude -I. -Ibenchmark/linux
105+
106+
103107
clean:
104108
rm -f $(OBJECTS) $(EXECUTABLES) $(EXTRA_EXECUTABLES)
105109

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Goal: Speed up the parsing of JSON per se.
77
## Code example
88

99
```C
10-
#include "jsonparser/jsonparser.h"
10+
#include "simdjson/jsonparser.h"
1111

1212
/...
1313

benchmark/minifiercompetition.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
#include <iostream>
33

44
#include "benchmark.h"
5-
#include "jsonparser/jsonioutil.h"
6-
#include "jsonparser/jsonminifier.h"
7-
#include "jsonparser/jsonparser.h"
5+
#include "simdjson/jsonioutil.h"
6+
#include "simdjson/jsonminifier.h"
7+
#include "simdjson/jsonparser.h"
88

99
// #define RAPIDJSON_SSE2 // bad
1010
// #define RAPIDJSON_SSE42 // bad

benchmark/parse.cpp

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
#include "jsonparser/common_defs.h"
2-
#include "linux-perf-events.h"
3-
#include <algorithm>
1+
#include <stdbool.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
#include <string.h>
5+
#include <unistd.h>
6+
#include <x86intrin.h>
7+
#include <ctype.h>
48
#include <assert.h>
9+
#include <dirent.h>
10+
#include <inttypes.h>
11+
12+
#include <algorithm>
513
#include <chrono>
614
#include <cstring>
7-
#include <dirent.h>
815
#include <fstream>
9-
#include <inttypes.h>
1016
#include <iomanip>
1117
#include <iostream>
1218
#include <map>
1319
#include <set>
1420
#include <sstream>
15-
#include <stdbool.h>
16-
#include <stdio.h>
17-
#include <stdlib.h>
18-
#include <string.h>
1921
#include <string>
20-
#include <unistd.h>
2122
#include <vector>
22-
#include <x86intrin.h>
23-
#include <ctype.h>
23+
24+
25+
#include "linux-perf-events.h"
2426

2527
//#define DEBUG
26-
#include "jsonparser/jsonparser.h"
27-
#include "jsonparser/jsonioutil.h"
28-
#include "jsonparser/simdjson_internal.h"
29-
#include "jsonparser/stage1_find_marks.h"
30-
#include "jsonparser/stage2_flatten.h"
31-
#include "jsonparser/stage34_unified.h"
28+
#include "simdjson/common_defs.h"
29+
#include "simdjson/jsonparser.h"
30+
#include "simdjson/jsonioutil.h"
31+
#include "simdjson/parsedjson.h"
32+
#include "simdjson/stage1_find_marks.h"
33+
#include "simdjson/stage2_flatten.h"
34+
#include "simdjson/stage34_unified.h"
3235
using namespace std;
3336

3437
int main(int argc, char *argv[]) {

benchmark/parsingcompetition.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
#include <unistd.h>
2-
#include "jsonparser/jsonparser.h"
2+
#include "simdjson/jsonparser.h"
33

44
#include "benchmark.h"
55

6-
// #define RAPIDJSON_SSE2 // bad
7-
// #define RAPIDJSON_SSE42 // bad
6+
// #define RAPIDJSON_SSE2 // bad for performance
7+
// #define RAPIDJSON_SSE42 // bad for performance
88
#include "rapidjson/document.h"
9-
#include "rapidjson/reader.h" // you have to check in the submodule
9+
#include "rapidjson/reader.h"
1010
#include "rapidjson/stringbuffer.h"
1111
#include "rapidjson/writer.h"
12+
1213
#include "json11.cpp"
1314
#include "sajson.h"
1415
#include "fastjson.cpp"
@@ -18,7 +19,6 @@ extern "C"
1819
{
1920
#include "ultrajsondec.c"
2021
#include "ujdecode.h"
21-
2222
}
2323
using namespace rapidjson;
2424
using namespace std;
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

3-
#include "jsonparser/common_defs.h"
4-
#include "jsonparser/simdjson_internal.h"
3+
#include "simdjson/common_defs.h"
4+
#include "simdjson/parsedjson.h"
55

66
// structural chars here are
77
// they are { 0x7b } 0x7d : 0x3a [ 0x5b ] 0x5d , 0x2c
@@ -109,4 +109,3 @@ inline size_t codepoint_to_utf8(uint32_t cp, u8 *c) {
109109
return 0; // bad r
110110
}
111111

112-

include/simdjson/jsonformatutils.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#pragma once
2+
3+
#include <stdio.h>
4+
5+
static inline void print_with_escapes(const unsigned char *src) {
6+
while (*src) {
7+
switch (*src) {
8+
case '\n':
9+
putchar('\\');
10+
putchar('n');
11+
break;
12+
case '\"':
13+
putchar('\\');
14+
putchar('"');
15+
break;
16+
case '\t':
17+
putchar('\\');
18+
putchar('t');
19+
break;
20+
case '\\':
21+
putchar('\\');
22+
putchar('\\');
23+
break;
24+
default:
25+
if (*src <= 0x1F) {
26+
printf("\\u%x", *src);
27+
} else
28+
putchar(*src);
29+
}
30+
src++;
31+
}
32+
}
33+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <sstream>
88
#include <string>
99

10-
#include "common_defs.h"
10+
#include "simdjson/common_defs.h"
1111

1212
// if you must provide a pointer to some data, create it with this function:
1313
// length is the max. size in bytes of the string

0 commit comments

Comments
 (0)