diff --git a/Makefile.am b/Makefile.am index 49140d759..ce095de3b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -7,7 +7,7 @@ json_unit_CXXFLAGS = $(FLAGS) -std=c++11 json_unit_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/test -Dprivate=public json_parser_SOURCES = src/JSON.cc src/JSON.h benchmark/parse.cc -json_parser_CXXFLAGS = $(FLAGS) -std=c++11 +json_parser_CXXFLAGS = -O3 -std=c++11 -flto json_parser_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/benchmark cppcheck: @@ -24,3 +24,6 @@ pretty: --align-reference=type --add-brackets --convert-tabs --close-templates \ --lineend=linux --preserve-date --suffix=none \ $(SOURCES) + +parser: + make CXXFLAGS="" json_parser \ No newline at end of file diff --git a/json_parser.py b/json_parser.py new file mode 100755 index 000000000..4e97b2cab --- /dev/null +++ b/json_parser.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python + +import sys +import json + +j = json.load(sys.stdin) diff --git a/src/JSON.cc b/src/JSON.cc index 5445404e4..43ae8026e 100644 --- a/src/JSON.cc +++ b/src/JSON.cc @@ -1776,8 +1776,15 @@ Initialize the JSON parser given an input stream \p _is. JSON::Parser::Parser(std::istream& _is) { // copy stream to string - std::istreambuf_iterator eos; - std::string string_input(std::istreambuf_iterator(_is), eos); + std::string input_line, string_input; + + // from http://www.manticmoo.com/articles/jeff/programming/c++/making-io-streams-efficient-in-c++.php + // Don't sync C++ and C I/O + std::ios_base::sync_with_stdio(false); + while(_is) { + std::getline(_is, input_line); + string_input += input_line; + } _length = string_input.size(); _buffer = new char[_length + 1];