+ guard call to std::ios_base::sync_with_stdio
This commit is contained in:
parent
9537c70b67
commit
481f377cfe
2 changed files with 16 additions and 3 deletions
15
src/JSON.cc
15
src/JSON.cc
|
@ -22,6 +22,7 @@
|
|||
////////////////////
|
||||
|
||||
std::mutex JSON::_token;
|
||||
bool JSON::Parser::firstCall = true;
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
|
@ -1776,9 +1777,17 @@ Initialize the JSON parser given an input stream \p _is.
|
|||
*/
|
||||
JSON::Parser::Parser(std::istream& _is)
|
||||
{
|
||||
// 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);
|
||||
// On first call, switch off syncing between C++ and C I/O. This call must
|
||||
// be done before first I/O operation as the behavior may be undefined
|
||||
// otherwise.
|
||||
if (firstCall)
|
||||
{
|
||||
firstCall = false;
|
||||
// Don't sync C++ and C I/O
|
||||
// from http://www.manticmoo.com/articles/jeff/programming/c++/making-io-streams-efficient-in-c++.php
|
||||
std::ios_base::sync_with_stdio(false);
|
||||
}
|
||||
|
||||
while (_is)
|
||||
{
|
||||
std::string input_line;
|
||||
|
|
|
@ -432,6 +432,10 @@ class JSON
|
|||
char _current {};
|
||||
/// the position inside the input buffer
|
||||
size_t _pos = 0;
|
||||
|
||||
private:
|
||||
/// variable to guard std::ios_base::sync_with_stdio
|
||||
static bool firstCall;
|
||||
};
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue