diff --git a/bench/bench.cpp b/bench/bench.cpp index 6925a5dd..588c3423 100644 --- a/bench/bench.cpp +++ b/bench/bench.cpp @@ -433,17 +433,24 @@ main( load_file(argv[i])}); } - std::vector> vi; - vi.reserve(10); - //vi.emplace_back(new boost_vec_impl); - vi.emplace_back(new boost_default_impl); - vi.emplace_back(new boost_impl); - vi.emplace_back(new rapidjson_impl); - //vi.emplace_back(new nlohmann_impl); + try + { + std::vector> vi; + vi.reserve(10); + //vi.emplace_back(new boost_vec_impl); + vi.emplace_back(new boost_default_impl); + vi.emplace_back(new boost_impl); + vi.emplace_back(new rapidjson_impl); + //vi.emplace_back(new nlohmann_impl); + + benchParse(vs, vi); + benchSerialize(vs, vi); + } + catch(system_error const& se) + { + dout << se.what() << std::endl; + } - benchParse(vs, vi); - //benchSerialize(vs, vi); - return 0; } diff --git a/include/boost/json/impl/serializer.ipp b/include/boost/json/impl/serializer.ipp index 75e372e1..2fc7486d 100644 --- a/include/boost/json/impl/serializer.ipp +++ b/include/boost/json/impl/serializer.ipp @@ -338,7 +338,7 @@ loop_str: *p++ = '\"'; stack_.front().st = state::str2; BOOST_FALLTHROUGH; -#if 1 + case state::str2: { auto s = str_.data(); @@ -356,16 +356,19 @@ loop_str: break; // fast loop + char const* ss = s; while(s < sn) { auto const ch = *s++; auto const c = esc[static_cast< unsigned char>(ch)]; if(! c) - { - *p++ = ch; continue; - } + auto const n = (s - ss) - 1; + std::memcpy(p, ss, n); + ss = s; + p += n; + *p++ = ch; *p++ = '\\'; *p++ = c; if(c != 'u') @@ -377,6 +380,9 @@ loop_str: *p++ = hex[static_cast< unsigned char>(ch) & 15]; } + auto const n = s - ss; + std::memcpy(p, ss, n); + p += n; } while(p < p1 && s < s1) { @@ -442,106 +448,6 @@ loop_str: state::str3; BOOST_FALLTHROUGH; } -#else - case state::str2: - { - auto s = str_.data(); - auto const s1 = - s + str_.size(); - if(static_cast( - p1 - p) >= 6 * str_.size()) - { - // fast loop - while(s < s1) - { - auto const ch = *s++; - auto const c = esc[static_cast< - unsigned char>(ch)]; - if(! c) - { - *p++ = ch; - continue; - } - *p++ = '\\'; - *p++ = c; - if(c != 'u') - continue; - *p++ = '0'; - *p++ = '0'; - *p++ = hex[static_cast< - unsigned char>(ch) >> 4]; - *p++ = hex[static_cast< - unsigned char>(ch) & 15]; - } - } - else - { - while(p < p1 && s < s1) - { - auto const ch = *s++; - auto const c = esc[static_cast< - unsigned char>(ch)]; - if(! c) - { - *p++ = ch; - continue; - } - if(c != 'u') - { - if(p + 2 <= p1) - { - *p++ = '\\'; - *p++ = c; - continue; - } - buf_[1] = '\\'; - buf_[0] = c; - nbuf_ = 2; - str_ = str_.substr( - s - str_.data()); - stack_.front().st = - state::str4; - goto loop; - } - if(p + 6 <= p1) - { - *p++ = '\\'; - *p++ = 'u'; - *p++ = '0'; - *p++ = '0'; - *p++ = hex[static_cast< - unsigned char>(ch) >> 4]; - *p++ = hex[static_cast< - unsigned char>(ch) & 15]; - continue; - } - buf_[5] = '\\'; - buf_[4] = 'u'; - buf_[3] = '0'; - buf_[2] = '0'; - buf_[1] = hex[static_cast< - unsigned char>(ch) >> 4]; - buf_[0] = hex[static_cast< - unsigned char>(ch) & 15]; - nbuf_ = 6; - str_ = str_.substr( - s - str_.data()); - stack_.front().st = - state::str4; - goto loop; - } - } - if(s < s1) - { - str_ = str_.substr( - s - str_.data()); - goto finish; - } - stack_.front().st = - state::str3; - BOOST_FALLTHROUGH; - } -#endif case state::str3: if(p >= p1) diff --git a/test/make-strings.py b/test/make-strings.py new file mode 100644 index 00000000..c8c1a9d8 --- /dev/null +++ b/test/make-strings.py @@ -0,0 +1,17 @@ +# Build array of random strings + +import os +import random +from random import randint + +def randstr(): + letters = "0123456789!@#$%^&*()_-+=[]{}|;:,<.>/?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + return ''.join(random.choice(letters) for i in range(randint(1, 2000))); + +print "["; +for i in range(1000): + print "\"", randstr(), "\","; +print "\"", randstr(), "\""; +print "]"; + +