Adding scalar minifier.
This commit is contained in:
parent
0f3d335755
commit
39e1169e8b
|
@ -1,6 +1,8 @@
|
|||
#include "avxprocessing.h"
|
||||
|
||||
#include "avxminifier.h"
|
||||
#include "scalarminifier.h"
|
||||
|
||||
#include "benchmark.h"
|
||||
#include "jsonstruct.h"
|
||||
// #define RAPIDJSON_SSE2 // bad
|
||||
|
@ -34,7 +36,7 @@ std::string rapidstringmeInsitu(char * json) {
|
|||
std::string rapidstringme(char * json) {
|
||||
Document d;
|
||||
d.Parse(json);
|
||||
if(d.HasParseError()) {
|
||||
if(d.HasParseError()) {
|
||||
std::cerr << "problem!" << std::endl;
|
||||
return "";// should do something
|
||||
}
|
||||
|
@ -117,14 +119,18 @@ int main(int argc, char *argv[]) {
|
|||
BEST_TIME_NOCHECK(rapidstringmeInsitu((char*) buffer), memcpy(buffer, p.first, p.second) , repeat, volume,
|
||||
true);
|
||||
memcpy(buffer, p.first, p.second);
|
||||
|
||||
size_t outlength = copy_without_useless_spaces((const uint8_t *)buffer, p.second,(uint8_t *) buffer);
|
||||
printf("these should match: %zu %zu \n", strlength, outlength);
|
||||
|
||||
|
||||
|
||||
uint8_t * cbuffer = (uint8_t *)buffer;
|
||||
BEST_TIME(copy_without_useless_spaces(cbuffer, p.second,cbuffer), outlength,
|
||||
memcpy(buffer, p.first, p.second), repeat, volume, true);
|
||||
|
||||
BEST_TIME(despace(cbuffer, p.second,cbuffer), outlength,
|
||||
memcpy(buffer, p.first, p.second), repeat, volume, true);
|
||||
|
||||
BEST_TIME(d.ParseInsitu(buffer).HasParseError(),false, cbuffer[copy_without_useless_spaces((const uint8_t *)p.first, p.second,cbuffer)]='\0' , repeat, volume,
|
||||
true);
|
||||
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
#include <stdint.h>
|
||||
|
||||
static uint8_t jump_table[256 * 3] = {
|
||||
0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0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 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
|
||||
0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0,
|
||||
1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1,
|
||||
1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
|
||||
0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1,
|
||||
};
|
||||
|
||||
static inline size_t despace(const unsigned char *bytes, size_t howmany,
|
||||
unsigned char *out) {
|
||||
size_t i = 0, pos = 0;
|
||||
uint8_t quote = 0;
|
||||
uint8_t nonescape = 1;
|
||||
|
||||
while (i < howmany) {
|
||||
unsigned char c = bytes[i];
|
||||
uint8_t *meta = jump_table + 3 * c;
|
||||
|
||||
quote = quote ^ (meta[0] & nonescape);
|
||||
out[pos] = c;
|
||||
pos += meta[2] | quote;
|
||||
|
||||
i += 1;
|
||||
nonescape = (~nonescape) | (meta[1]);
|
||||
}
|
||||
return pos;
|
||||
}
|
Loading…
Reference in New Issue