Skip to content

Commit 2b853c4

Browse files
committed
Got rid of several unnecessary includes of <iostream>.
Including <iostream> causes the file to be polluted with a static initializer for the __ioinit symbol. This can harm binary startup time. For more info, see here: http://neugierig.org/software/chromium/notes/2011/08/static-initializers.html
1 parent 7c507d7 commit 2b853c4

File tree

6 files changed

+15
-8
lines changed

6 files changed

+15
-8
lines changed

include/json/assertions.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# define CPPTL_JSON_ASSERTIONS_H_INCLUDED
88

99
#include <stdlib.h>
10-
#include <iostream>
1110

1211
#if !defined(JSON_IS_AMALGAMATION)
1312
# include <json/config.h>
@@ -18,7 +17,13 @@
1817
#define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message );
1918
#else // JSON_USE_EXCEPTION
2019
#define JSON_ASSERT( condition ) assert( condition );
21-
#define JSON_FAIL_MESSAGE( message ) { std::cerr << std::endl << message << std::endl; exit(123); }
20+
21+
// The call to assert() will show the failure message in debug builds. In
22+
// release bugs we write to invalid memory in order to crash hard instead of
23+
// calling exit(), so that a debugger or crash reporter gets the chance to take
24+
// over.
25+
#define JSON_FAIL_MESSAGE( message ) { assert(false && message); strcpy(reinterpret_cast<char*>(666), message); }
26+
2227
#endif
2328

2429
#define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) { JSON_FAIL_MESSAGE( message ) }

include/json/reader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# include <deque>
1414
# include <stack>
1515
# include <string>
16-
# include <iostream>
1716

1817
namespace Json {
1918

include/json/writer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#endif // if !defined(JSON_IS_AMALGAMATION)
1212
# include <vector>
1313
# include <string>
14-
# include <iostream>
1514

1615
namespace Json {
1716

src/lib_json/json_reader.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include <cstdio>
1414
#include <cassert>
1515
#include <cstring>
16-
#include <iostream>
1716
#include <stdexcept>
1817

1918
#if _MSC_VER >= 1400 // VC++ 8.0
@@ -904,7 +903,14 @@ std::istream& operator>>( std::istream &sin, Value &root )
904903
{
905904
Json::Reader reader;
906905
bool ok = reader.parse(sin, root, true);
907-
if (!ok) JSON_FAIL_MESSAGE(reader.getFormattedErrorMessages());
906+
if (!ok) {
907+
fprintf(
908+
stderr,
909+
"Error from reader: %s",
910+
reader.getFormattedErrorMessages().c_str());
911+
912+
JSON_FAIL_MESSAGE("reader error");
913+
}
908914
return sin;
909915
}
910916

src/lib_json/json_value.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
# endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR
1313
#endif // if !defined(JSON_IS_AMALGAMATION)
1414
#include <math.h>
15-
#include <iostream>
1615
#include <sstream>
1716
#include <utility>
1817
#include <stdexcept>

src/lib_json/json_writer.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <assert.h>
1212
#include <stdio.h>
1313
#include <string.h>
14-
#include <iostream>
1514
#include <sstream>
1615
#include <iomanip>
1716

0 commit comments

Comments
 (0)