Skip to content

Commit f8543bf

Browse files
Introduce new and more flexible API grapheme_line_segmenter, replacing scan API
Signed-off-by: Christian Parpart <[email protected]>
1 parent 1b88442 commit f8543bf

11 files changed

+1575
-869
lines changed

CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ option(LIBUNICODE_BENCHMARK "libunicode: Enables building of benchmark for libun
4747
option(LIBUNICODE_TOOLS "libunicode: Builds CLI tools [default: ${MASTER_PROJECT}]" ${MASTER_PROJECT})
4848
option(LIBUNICODE_BUILD_STATIC "libunicode: provide static library instead of dynamic [default: ${LIBUNICODE_BUILD_STATIC_DEFAULT}]" ${LIBUNICODE_BUILD_STATIC_DEFAULT})
4949
option(LIBUNICODE_USE_INTRINSICS "libunicode: Use SIMD extenstion during text read [default: ON]" ON)
50-
option(LIBUNICODE_USE_STD_SIMD "libunicode: Use std::simd as SIMD extenstion during text read (takes precedence over own intrinsics) [default: ON]" ${LIBUNICODE_USE_INTRINSICS})
50+
option(LIBUNICODE_USE_STD_SIMD "libunicode: Use std::simd as SIMD extenstion during text read (takes precedence over own intrinsics) [default: ON]" ON)
5151
option(LIBUNICODE_TABLEGEN_FASTBUILD "libunicode: Use fast table generation (takes more memory in final tables) [default: OFF]" OFF)
5252

5353
set(BENCHMARK_ENABLE_TESTING OFF CACHE BOOL "Enable testing of the benchmark library." FORCE)

cmake/presets/common.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"version": 6,
33
"configurePresets": [
4-
{ "name": "debug", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "LIBUNICODE_TABLEGEN_FASTBUILD": "ON" } },
4+
{ "name": "debug", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug", "LIBUNICODE_TABLEGEN_FASTBUILD": "ON", "LIBUNICODE_TRACE": "ON" } },
55
{ "name": "release", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" } },
66
{ "name": "arch-native", "hidden": true, "cacheVariables": { "CMAKE_CXX_FLAGS": "-march=native" } },
77
{ "name": "clang", "hidden": true, "cacheVariables": { "CMAKE_CXX_COMPILER": "clang++" } },

src/libunicode/CMakeLists.txt

+10-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
include(GNUInstallDirs)
22

3+
option(LIBUNICODE_TRACE "Enable trace logging" OFF)
4+
35
function(ExtractZipArchive ZIP_FILE OUTPUT_DIR)
46
if(CMAKE_VERSION VERSION_LESS 3.18)
57
# Use the older method for versions prior to CMake 3.18
@@ -102,7 +104,6 @@ add_library(unicode ${LIBUNICODE_LIB_MODE}
102104
codepoint_properties.cpp
103105
emoji_segmenter.cpp
104106
grapheme_segmenter.cpp
105-
scan.cpp
106107
script_segmenter.cpp
107108
utf8.cpp
108109
width.cpp
@@ -114,22 +115,22 @@ add_library(unicode ${LIBUNICODE_LIB_MODE}
114115
)
115116

116117
if(LIBUNICODE_USE_STD_SIMD)
117-
target_compile_definitions(unicode PRIVATE LIBUNICODE_USE_STD_SIMD)
118+
target_compile_definitions(unicode PUBLIC LIBUNICODE_USE_STD_SIMD)
118119
endif()
119120
if(LIBUNICODE_USE_INTRINSICS)
120-
target_compile_definitions(unicode PRIVATE USE_INTRINSICS)
121+
target_compile_definitions(unicode PUBLIC LIBUNICODE_USE_INTRINSICS)
121122
endif()
122123

123124
set(public_headers
124125
capi.h
125126
codepoint_properties.h
126127
convert.h
127128
emoji_segmenter.h
129+
grapheme_line_segmenter.h
128130
grapheme_segmenter.h
129131
intrinsics.h
130132
multistage_table_view.h
131133
run_segmenter.h
132-
scan.h
133134
script_segmenter.h
134135
support.h
135136
utf8.h
@@ -150,6 +151,10 @@ set_target_properties(unicode PROPERTIES
150151
SOVERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}"
151152
)
152153

154+
if(LIBUNICODE_TRACE)
155+
target_compile_definitions(unicode PUBLIC LIBUNICODE_TRACE)
156+
endif()
157+
153158
add_library(unicode::unicode ALIAS unicode)
154159
add_library(unicode::core ALIAS unicode)
155160
target_include_directories(unicode PUBLIC $<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/src>
@@ -161,7 +166,6 @@ add_executable(unicode_tablegen tablegen.cpp)
161166
set_target_properties(unicode_tablegen PROPERTIES CMAKE_BUILD_TYPE Release)
162167
target_link_libraries(unicode_tablegen PRIVATE unicode::loader)
163168

164-
165169
# {{{ installation
166170
set(LIBUNICODE_CMAKE_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/libunicode" CACHE PATH "Installation directory for cmake files, a relative path that will be joined with ${CMAKE_INSTALL_PREFIX} or an absolute path.")
167171
set(LIBUNICODE_INSTALL_CMAKE_FILES ${MASTER_PROJECT} CACHE BOOL "Decides whether or not to install CMake config and -version files.")
@@ -220,9 +224,9 @@ if(LIBUNICODE_TESTING)
220224
capi_test.cpp
221225
convert_test.cpp
222226
emoji_segmenter_test.cpp
227+
grapheme_line_segmenter_test.cpp
223228
grapheme_segmenter_test.cpp
224229
run_segmenter_test.cpp
225-
scan_test.cpp
226230
script_segmenter_test.cpp
227231
test_main.cpp
228232
unicode_test.cpp
@@ -247,8 +251,6 @@ if(LIBUNICODE_TESTING)
247251
endif()
248252
# }}}
249253

250-
251-
252254
# {{{ unicode_test
253255
if(LIBUNICODE_BENCHMARK)
254256
if(NOT benchmark_FOUND)

src/libunicode/benchmark.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <libunicode/convert.h>
2-
#include <libunicode/scan.h>
2+
#include <libunicode/grapheme_line_segmenter.h>
33
#include <libunicode/utf8.h>
44

55
#include <string_view>
@@ -14,7 +14,7 @@ static void benchmarkWithLength(benchmark::State& benchmarkState)
1414
auto TestText = std::string(L, 'a') + "\u00A9";
1515
for (auto _: benchmarkState)
1616
{
17-
benchmark::DoNotOptimize(unicode::detail::scan_for_text_ascii(TestText, L + 10));
17+
benchmark::DoNotOptimize(unicode::detail::process_only_ascii(std::string_view(TestText).substr(0, L + 10)));
1818
}
1919
}
2020

@@ -24,7 +24,9 @@ static void benchmarkWithOffset(benchmark::State& benchmarkState)
2424
auto TestText = std::string(L, 'a') + "\U0001F600" + std::string(1000, 'a');
2525
for (auto _: benchmarkState)
2626
{
27-
benchmark::DoNotOptimize(unicode::detail::scan_for_text_ascii(TestText, L + 10));
27+
auto state = unicode::detail::unicode_process_state {};
28+
auto eventHandler = unicode::detail::EventHandler{};
29+
benchmark::DoNotOptimize(unicode::detail::process_only_complex_unicode(eventHandler, state, TestText, L + 10));
2830
}
2931
}
3032

0 commit comments

Comments
 (0)