Skip to content

Commit 362127b

Browse files
Merge pull request #54 from contour-terminal/improvement/eradicate-gsl-dependency
Remove use of gsl::span to reduce dependencies (Microsoft.GSL).
2 parents 9a830b2 + 0b0f53c commit 362127b

File tree

10 files changed

+41
-93
lines changed

10 files changed

+41
-93
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Add access to the assigned name of a codepoint.
77
- unicode-query: Now also prints name and age properties.
88
- CMake install target also installs header and library (not just tools).
9+
- Reduce number of dependencies down to fmtlib and (for unit tests) Catch2.
910

1011
## 0.1.0 (2022-11-03)
1112

cmake/ThirdParties.cmake

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,33 +49,11 @@ else()
4949
set(THIRDPARTY_BUILTIN_fmt "system package")
5050
endif()
5151

52-
if(TARGET GSL)
53-
set(THIRDPARTY_BUILTIN_GSL "embedded")
54-
else()
55-
set(THIRDPARTY_BUILTIN_GSL "system package")
56-
if (WIN32)
57-
# On Windows we use vcpkg and there the name is different
58-
find_package(Microsoft.GSL CONFIG REQUIRED)
59-
#target_link_libraries(main PRIVATE Microsoft.GSL::GSL)
60-
else()
61-
find_package(Microsoft.GSL REQUIRED)
62-
endif()
63-
endif()
64-
65-
if (TARGET range-v3)
66-
set(THIRDPARTY_BUILTIN_range_v3 "embedded")
67-
else()
68-
find_package(range-v3 REQUIRED)
69-
set(THIRDPARTY_BUILTIN_range_v3 "system package")
70-
endif()
71-
7252
macro(ThirdPartiesSummary2)
7353
message(STATUS "==============================================================================")
7454
message(STATUS " ThirdParties")
7555
message(STATUS "------------------------------------------------------------------------------")
7656
message(STATUS "Catch2 ${THIRDPARTY_BUILTIN_Catch2}")
77-
message(STATUS "GSL ${THIRDPARTY_BUILTIN_GSL}")
7857
message(STATUS "fmt ${THIRDPARTY_BUILTIN_fmt}")
79-
message(STATUS "range-v3 ${THIRDPARTY_BUILTIN_range_v3}")
8058
message(STATUS "------------------------------------------------------------------------------")
8159
endmacro()

scripts/install-deps.ps1

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ class ThirdParty
1313
# Take care, order matters, at least as much as dependencies are of concern.
1414
$ThirdParties =
1515
@(
16-
[ThirdParty]@{
17-
Folder="GSL-3.1.0";
18-
Archive="gsl-3.1.0.zip";
19-
URI="https://github.com/microsoft/GSL/archive/refs/tags/v3.1.0.zip"
20-
};
2116
[ThirdParty]@{
2217
Folder="Catch2-2.13.7";
2318
Archive="Catch2-2.13.7.zip";

scripts/install-deps.sh

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ fetch_and_unpack_fmtlib()
7878
https://github.com/fmtlib/fmt/archive/refs/tags/9.1.0.tar.gz
7979
}
8080

81-
fetch_and_unpack_gsl()
82-
{
83-
fetch_and_unpack \
84-
GSL-3.1.0 \
85-
gsl-3.1.0.tar.gz \
86-
https://github.com/microsoft/GSL/archive/refs/tags/v3.1.0.tar.gz
87-
}
88-
8981
fetch_and_unpack_yaml_cpp()
9082
{
9183
fetch_and_unpack \
@@ -137,7 +129,6 @@ install_deps_ubuntu()
137129
fi
138130
fi
139131

140-
fetch_and_unpack_gsl
141132
case $RELEASE in
142133
"18.04" | "19.04" | "20.04" | "21.04")
143134
# Older Ubuntu's don't have a recent enough fmt / range-v3, so supply it.
@@ -168,7 +159,6 @@ install_deps_FreeBSD()
168159
catch \
169160
cmake \
170161
libfmt \
171-
microsoft-gsl \
172162
ninja \
173163
pkgconf \
174164
range-v3
@@ -184,15 +174,19 @@ install_deps_arch()
184174
catch2 \
185175
cmake \
186176
git \
187-
microsoft-gsl \
188177
ninja \
189178
range-v3
190179
}
191180

192181
install_deps_fedora()
193182
{
194-
fetch_and_unpack_gsl
195-
fetch_and_unpack_fmtlib
183+
version=`cat /etc/fedora-release | awk '{print $3}'`
184+
185+
# Fedora 37+ contains fmtlib 9.1.0+, prefer this and fallback to embedding otherwise.
186+
should_embed_fmtlib=yes
187+
[ $version -ge 37 ] && should_embed_fmtlib=no
188+
189+
[ x$should_embed_fmtlib = xyes ] && fetch_and_unpack_fmtlib
196190
[ x$PREPARE_ONLY_EMBEDS = xON ] && return
197191

198192
# catch-devel
@@ -204,7 +198,7 @@ install_deps_fedora()
204198
pkgconf
205199
range-v3-devel
206200
"
207-
# Sadly, gsl-devel system package is too old to be used.
201+
[ x$should_embed_fmtlib != xyes ] || packages="$packages fmt-devel"
208202
sudo dnf install $SYSDEP_ASSUME_YES $packages
209203
}
210204

@@ -218,7 +212,6 @@ install_deps_darwin()
218212
# NB: Also available in brew: mimalloc
219213
# catch2: available in brew, but too new (version 3+)
220214
brew install $SYSDEP_ASSUME_YES \
221-
cpp-gsl \
222215
fmt \
223216
pkg-config \
224217
range-v3

src/unicode/CMakeLists.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ add_library(unicode_ucd STATIC
3636
)
3737
add_library(unicode::ucd ALIAS unicode_ucd)
3838
target_include_directories(unicode_ucd PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src)
39-
target_link_libraries(unicode_ucd PUBLIC fmt::fmt-header-only Microsoft.GSL::GSL)
39+
target_link_libraries(unicode_ucd PUBLIC fmt::fmt-header-only)
4040

4141
# =========================================================================================================
4242

@@ -60,7 +60,7 @@ add_custom_command(
6060
add_library(unicode_loader STATIC codepoint_properties_loader.h codepoint_properties_loader.cpp)
6161
add_library(unicode::loader ALIAS unicode_loader)
6262
target_include_directories(unicode_loader PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src)
63-
target_link_libraries(unicode_loader PUBLIC fmt::fmt-header-only Microsoft.GSL::GSL unicode::ucd)
63+
target_link_libraries(unicode_loader PUBLIC fmt::fmt-header-only unicode::ucd)
6464

6565
# =========================================================================================================
6666

@@ -98,15 +98,15 @@ set_target_properties(unicode PROPERTIES PUBLIC_HEADER "${public_headers}")
9898

9999
add_library(unicode::core ALIAS unicode)
100100
target_include_directories(unicode PUBLIC ${PROJECT_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src)
101-
target_link_libraries(unicode PUBLIC unicode::ucd fmt::fmt-header-only Microsoft.GSL::GSL)
101+
target_link_libraries(unicode PUBLIC unicode::ucd fmt::fmt-header-only)
102102

103103
install(TARGETS unicode
104104
LIBRARY DESTINATION lib
105105
PUBLIC_HEADER DESTINATION include/unicode)
106106

107107
add_executable(unicode_tablegen tablegen.cpp)
108108
target_include_directories(unicode_tablegen PRIVATE ${PROJECT_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src)
109-
target_link_libraries(unicode_tablegen PRIVATE unicode::loader fmt::fmt-header-only Microsoft.GSL::GSL)
109+
target_link_libraries(unicode_tablegen PRIVATE unicode::loader fmt::fmt-header-only)
110110

111111
# --------------------------------------------------------------------------------------------------------
112112
# unicode_test

src/unicode/codepoint_properties.cpp

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@
1717
namespace unicode
1818
{
1919

20-
using table_view = codepoint_properties::tables_view;
21-
22-
codepoint_properties::tables_view codepoint_properties::configured_tables {
23-
gsl::span<table_view::stage1_element_type const>(precompiled::stage1.data(), precompiled::stage1.size()),
24-
gsl::span<table_view::stage2_element_type const>(precompiled::stage2.data(), precompiled::stage2.size()),
25-
gsl::span<codepoint_properties const>(precompiled::properties.data(), precompiled::properties.size())
26-
};
20+
codepoint_properties::tables_view codepoint_properties::configured_tables { precompiled::stage1.data(),
21+
precompiled::stage2.data(),
22+
precompiled::properties.data() };
2723

2824
codepoint_properties::names_view codepoint_properties::configured_names {
29-
gsl::span<table_view::stage1_element_type const>(precompiled::names_stage1.data(),
30-
precompiled::names_stage1.size()),
31-
gsl::span<table_view::stage2_element_type const>(precompiled::names_stage2.data(),
32-
precompiled::names_stage2.size()),
33-
gsl::span<std::string_view const>(precompiled::names_stage3.data(), precompiled::names_stage3.size())
25+
precompiled::names_stage1.data(),
26+
precompiled::names_stage2.data(),
27+
precompiled::names_stage3.data(),
3428
};
3529

3630
} // namespace unicode

src/unicode/codepoint_properties.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include <unicode/support/multistage_table_view.h>
1919
#include <unicode/ucd_enums.h> // Only for the UCD enums.
2020

21-
#include <gsl/span>
22-
2321
#include <type_traits>
2422

2523
namespace unicode

src/unicode/codepoint_properties_loader.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -638,14 +638,12 @@ namespace
638638
{
639639
{
640640
auto const _ = scoped_timer { _log, "Creating multistage tables (properties)" };
641-
auto input = gsl::span<codepoint_properties const>(_codepoints.data(), _codepoints.size());
642-
support::generate(input, _output);
641+
support::generate(_codepoints.data(), _codepoints.size(), _output);
643642
}
644643

645644
{
646645
auto const _ = scoped_timer { _log, "Creating multistage tables (names)" };
647-
auto const names = gsl::span<string const>(_names.data(), _names.size());
648-
support::generate(names, _outputNames);
646+
support::generate(_names.data(), _names.size(), _outputNames);
649647
}
650648
}
651649
} // namespace

src/unicode/support/multistage_table_generator.h

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818

1919
#include <fmt/format.h>
2020

21-
#include <gsl/span>
22-
#include <gsl/span_ext>
23-
2421
#include <algorithm>
2522
#include <cassert>
2623
#include <cstdint>
@@ -48,12 +45,7 @@ struct multistage_table
4845
std::vector<Stage2ElementType> stage2; // mod
4946
std::vector<T> stage3; // values
5047

51-
auto to_view() const noexcept
52-
{
53-
return view_type { gsl::span<Stage1ElementType const>(stage1.data(), stage1.size()),
54-
gsl::span<Stage2ElementType const>(stage2.data(), stage2.size()),
55-
gsl::span<T const>(stage3.data(), stage3.size()) };
56-
}
48+
auto to_view() const noexcept { return view_type { stage1.data(), stage2.data(), stage3.data() }; }
5749

5850
T const& get(SourceType index) const noexcept { return to_view().get(index); }
5951
};
@@ -67,20 +59,21 @@ template <typename T,
6759
class multistage_table_generator
6860
{
6961
public:
70-
gsl::span<T const> _input;
62+
T const* _input;
63+
size_t _inputSize;
7164
multistage_table<T, SourceType, Stage1ElementType, Stage2ElementType, BlockSize, MaxValue>& _output;
7265

7366
void generate()
7467
{
75-
assert(_input.size() % BlockSize == 0);
76-
_output.stage1.resize(_input.size());
77-
for (SourceType blockStart = 0; blockStart <= _input.size() - BlockSize; blockStart += BlockSize)
68+
assert(_inputSize % BlockSize == 0);
69+
_output.stage1.resize(_inputSize);
70+
for (SourceType blockStart = 0; blockStart <= _inputSize - BlockSize; blockStart += BlockSize)
7871
_output.stage1[blockStart / BlockSize] = get_or_create_index_to_stage2_block(blockStart);
7972
}
8073

8174
void verify() const
8275
{
83-
for (SourceType blockStart = 0; blockStart <= _input.size() - BlockSize; ++blockStart)
76+
for (SourceType blockStart = 0; blockStart <= _inputSize - BlockSize; ++blockStart)
8477
verify_block(blockStart / BlockSize);
8578
}
8679

@@ -124,7 +117,7 @@ class multistage_table_generator
124117
std::optional<size_t> find_same_block(size_t blockStart) const noexcept
125118
{
126119
assert(blockStart % BlockSize == 0);
127-
assert(blockStart + BlockSize <= _input.size());
120+
assert(blockStart + BlockSize <= _inputSize);
128121

129122
for (size_t otherBlockStart = 0; otherBlockStart < blockStart; otherBlockStart += BlockSize)
130123
if (is_same_block(otherBlockStart, blockStart))
@@ -139,8 +132,8 @@ class multistage_table_generator
139132
{
140133
assert(a % BlockSize == 0);
141134
assert(b % BlockSize == 0);
142-
assert(a + BlockSize <= _input.size());
143-
assert(b + BlockSize <= _input.size());
135+
assert(a + BlockSize <= _inputSize);
136+
assert(b + BlockSize <= _inputSize);
144137

145138
for (size_t i = 0; i < BlockSize; ++i)
146139
if (_input[a + i] != _input[b + i])
@@ -170,12 +163,13 @@ template <typename T,
170163
SourceType BlockSize,
171164
SourceType MaxValue = std::numeric_limits<SourceType>::max()>
172165
void generate(
173-
gsl::span<T const> input,
166+
T const* input,
167+
size_t inputSize,
174168
multistage_table<T, SourceType, Stage1ElementType, Stage2ElementType, BlockSize, MaxValue>& output)
175169
{
176170
auto builder =
177171
multistage_table_generator<T, SourceType, Stage1ElementType, Stage2ElementType, BlockSize, MaxValue> {
178-
input, output
172+
input, inputSize, output
179173
};
180174
builder.generate();
181175
}

src/unicode/support/multistage_table_view.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
*/
1414
#pragma once
1515

16-
#include <gsl/span>
17-
#include <gsl/span_ext>
18-
1916
#include <cstdint>
2017
#include <limits>
2118

@@ -35,13 +32,13 @@ struct multistage_table_view
3532
using stage2_element_type = Stage2ElementType;
3633
using value_type = T;
3734

38-
gsl::span<stage1_element_type const> stage1; // div
39-
gsl::span<stage2_element_type const> stage2; // mod
40-
gsl::span<value_type const> stage3; // values
35+
stage1_element_type const* stage1; // div
36+
stage2_element_type const* stage2; // mod
37+
value_type const* stage3; // values
4138

4239
static size_t constexpr block_size = BlockSize;
4340

44-
size_t size() const noexcept { return stage1.size(); }
41+
// size_t size() const noexcept { return stage1.size(); }
4542

4643
value_type const& get(source_type index, source_type fallback = source_type {}) const noexcept
4744
{
@@ -50,11 +47,11 @@ struct multistage_table_view
5047

5148
value_type const& unsafe_get(source_type index) const noexcept
5249
{
53-
auto const block_number = stage1.data()[index / BlockSize];
50+
auto const block_number = stage1[index / BlockSize];
5451
auto const block_start = block_number * BlockSize;
5552
auto const element_offset = index % BlockSize;
56-
auto const property_index = stage2.data()[block_start + element_offset];
57-
return stage3.data()[property_index];
53+
auto const property_index = stage2[block_start + element_offset];
54+
return stage3[property_index];
5855
}
5956
};
6057

0 commit comments

Comments
 (0)