Skip to content

Commit c912ade

Browse files
committed
Try to fix issue with escape_json
1 parent 899ad05 commit c912ade

File tree

3 files changed

+25
-27
lines changed

3 files changed

+25
-27
lines changed

binlog_json_parser/CMakeLists.txt

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ project(binlog_json_parser)
55
set(CMAKE_CXX_STANDARD 23)
66
set(CMAKE_CXX_STANDARD_REQUIRED ON)
77

8+
include(CheckIPOSupported)
9+
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_OUTPUT)
10+
11+
if(IPO_SUPPORTED)
12+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
13+
message(STATUS "Interprocedural optimization (IPO/LTO) enabled globally.")
14+
else()
15+
message(STATUS "IPO/LTO is not supported: ${IPO_OUTPUT}")
16+
endif()
17+
818
# Check if the build type is Release
919
if(CMAKE_BUILD_TYPE STREQUAL "Release")
10-
1120
# Set optimization level to -O3 for release builds
1221
if(NOT CMAKE_CXX_FLAGS_RELEASE MATCHES "-O")
1322
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
@@ -32,24 +41,9 @@ if(CMAKE_BUILD_TYPE STREQUAL "Release")
3241
message(WARNING "The -march option will not be set because the system is not x86 or x64.")
3342
endif()
3443

35-
# Check for LTO support
36-
include(CheckCXXCompilerFlag)
37-
38-
check_cxx_compiler_flag("-flto" COMPILER_SUPPORTS_LTO)
39-
40-
if(COMPILER_SUPPORTS_LTO)
41-
message(STATUS "Link Time Optimization (LTO) is supported by the compiler.")
42-
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -flto")
43-
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -flto")
44-
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -flto")
45-
else()
46-
message(WARNING "Link Time Optimization (LTO) is not supported by the compiler.")
47-
endif()
48-
4944
# Export compile flags to a file
5045
file(WRITE "${CMAKE_BINARY_DIR}/compile_flags.txt" "CXXFLAGS: ${CMAKE_CXX_FLAGS_RELEASE}\n")
5146
file(APPEND "${CMAKE_BINARY_DIR}/compile_flags.txt" "LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}\n")
52-
5347
endif()
5448

5549
add_library(mysqljsonparse SHARED mysqljsonparse.cpp mysql_json_parser.cpp)

binlog_json_parser/mysql_json_parser.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -120,24 +120,28 @@ static bool read_variable_length(const char *data, size_t data_length,
120120

121121
std::string escape_json(const std::string &s) {
122122
std::ostringstream o;
123-
for (auto c = s.cbegin(); c != s.cend(); c++) {
124-
switch (*c) {
125-
case '"': o << "\\\""; break;
123+
124+
for (const unsigned char uc : s) {
125+
switch (uc) {
126+
case '"': o << "\\\""; break;
126127
case '\\': o << "\\\\"; break;
127-
case '\b': o << "\\b"; break;
128-
case '\f': o << "\\f"; break;
129-
case '\n': o << "\\n"; break;
130-
case '\r': o << "\\r"; break;
131-
case '\t': o << "\\t"; break;
128+
case '\b': o << "\\b"; break;
129+
case '\f': o << "\\f"; break;
130+
case '\n': o << "\\n"; break;
131+
case '\r': o << "\\r"; break;
132+
case '\t': o << "\\t"; break;
133+
132134
default:
133-
if (*c <= '\x1f') {
135+
if (uc <= 0x1F) {
134136
o << "\\u"
135-
<< std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(*c);
137+
<< std::hex << std::setw(4) << std::setfill('0') << static_cast<int>(uc)
138+
<< std::dec;
136139
} else {
137-
o << *c;
140+
o << static_cast<char>(uc);
138141
}
139142
}
140143
}
144+
141145
return o.str();
142146
}
143147

-4.97 KB
Binary file not shown.

0 commit comments

Comments
 (0)