Skip to content

Commit

Permalink
Обновление core_as::str, небольшие оптимизации
Browse files Browse the repository at this point in the history
  • Loading branch information
orefkov committed Nov 11, 2023
1 parent 6e45773 commit daa76bb
Show file tree
Hide file tree
Showing 18 changed files with 19,493 additions and 7,965 deletions.
17 changes: 9 additions & 8 deletions include/core_as/core_as_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,16 @@
#endif


enum class LogLevel {
Critical,
Warning,
Normal,
Info,
Diagnostic
};

COREAS_API void* core_as_malloc(size_t count);
COREAS_API void* core_as_realloc(void* ptr, size_t count);
COREAS_API void core_as_free(void* ptr);
COREAS_API void core_as_print(const wchar_t* text);

const bool isWindowsOs = // NOLINT
#ifdef _WIN32
true
#else
false
#endif
;
const bool isx64 = sizeof(void*) == 8; // NOLINT
1,351 changes: 777 additions & 574 deletions include/core_as/str/sstring.h

Large diffs are not rendered by default.

57 changes: 23 additions & 34 deletions include/core_as/str/strexpr.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,29 @@
* База для строковых конкатенаций через выражения времени компиляции
*/
#pragma once
#include <uchar.h>
#include <algorithm>
#include <string_view>
#include <type_traits>

namespace core_as::str {

// Выводим типы для 16 и 32 битных символов взависимости от размера wchar_t
template<size_t N>
struct _wchar_type {
using type = char32_t;
};

template<>
struct _wchar_type<2> {
using type = char16_t; // Для совместимости с Windows
};

using wchar_type = _wchar_type<sizeof(wchar_t)>::type;
using wchar_type = std::conditional<sizeof(wchar_t) == 2, char16_t, char32_t>::type;

static wchar_type* to_w(wchar_t* p) {
inline wchar_type* to_w(wchar_t* p) {
return (reinterpret_cast<wchar_type*>(p));
}

static const wchar_type* to_w(const wchar_t* p) {
inline const wchar_type* to_w(const wchar_t* p) {
return (reinterpret_cast<const wchar_type*>(p));
}

using u8symbol = char;
using uwsymbol = wchar_t;
using u16symbol = char16_t;
using u32symbol = char32_t;
using u8s = char;
using uws = wchar_t;
using u16s = char16_t;
using u32s = char32_t;

//using size_t = size_t;// unsigned int;
using uu8symbol = std::make_unsigned<u8symbol>::type;
using uu8s = std::make_unsigned<u8s>::type;

template<typename A, typename K>
concept StrType = requires(const A& a) {
Expand Down Expand Up @@ -78,7 +67,7 @@ struct strexprjoin {
};

template<StrExpr A, StrExprForType<typename A::symb_type> B>
static auto operator & (const A& a, const B& b) {
inline auto operator & (const A& a, const B& b) {
return strexprjoin<A, B>{a, b};
}

Expand Down Expand Up @@ -108,10 +97,10 @@ struct empty_expr {
constexpr symb_type* place(symb_type* p) const noexcept { return p; }
};

inline constexpr empty_expr<u8symbol> eea{};
inline constexpr empty_expr<wchar_t> eew{};
inline constexpr empty_expr<u16symbol> eeu{};
inline constexpr empty_expr<u32symbol> eeuu{};
inline constexpr empty_expr<u8s> eea{};
inline constexpr empty_expr<uws> eew{};
inline constexpr empty_expr<u16s> eeu{};
inline constexpr empty_expr<u32s> eeuu{};

template<typename K>
struct expr_char {
Expand All @@ -126,7 +115,7 @@ struct expr_char {
};

template<typename K, StrExprForType<K> A>
constexpr static auto operator & (const A& a, K s) {
constexpr inline auto operator & (const A& a, K s) {
return strexprjoin_c<A, expr_char<K>>{ a, s };
}

Expand All @@ -143,7 +132,7 @@ struct expr_literal {
};

template<typename K, size_t N>
constexpr static auto e_t(const K(&s)[N]) {
constexpr inline auto e_t(const K(&s)[N]) {
return expr_literal<K, static_cast<size_t>(N - 1)>{ s };
}

Expand Down Expand Up @@ -173,12 +162,12 @@ struct expr_literal_join {
};

template<typename K, StrExprForType<K> A, size_t N>
constexpr static auto operator & (const A& a, const K(&s)[N]) {
constexpr inline auto operator & (const A& a, const K(&s)[N]) {
return expr_literal_join<false, K, (N - 1), A>{ s, a };
}

template<typename K, StrExprForType<K> A, size_t N>
constexpr static auto operator & (const K(&s)[N], const A& a) {
constexpr inline auto operator & (const K(&s)[N], const A& a) {
return expr_literal_join<true, K, (N - 1), A>{ s, a };
}

Expand All @@ -194,13 +183,13 @@ struct expr_spaces {
};

template<size_t N>
constexpr static auto e_spca() {
return expr_spaces<u8symbol, N>();
constexpr inline auto e_spca() {
return expr_spaces<u8s, N>();
}

template<size_t N>
constexpr static auto e_spcw() {
return expr_spaces<u16symbol, N>();
constexpr inline auto e_spcw() {
return expr_spaces<uws, N>();
}

template<typename K>
Expand All @@ -217,7 +206,7 @@ struct expr_pad {
};

template<typename K>
constexpr static auto e_c(K s, size_t l) {
constexpr inline auto e_c(K s, size_t l) {
return expr_pad<K>{ s, l };
}

Expand Down
5 changes: 4 additions & 1 deletion libs/core_as/str/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
cmake_minimum_required (VERSION 3.15)

# Add source to this project's executable.
add_library (core_as_str "sstring.cpp" "simple_unicode.cpp")
add_library (core_as_str
sstring.cpp
simple_unicode.cpp
)

if (BUILD_TESTS)
add_subdirectory(tests)
Expand Down
2 changes: 1 addition & 1 deletion libs/core_as/str/bench/bench_str.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int to_int(const std::string_view& s) {
return i3;
}

template<StrType<u8symbol> T>
template<StrType<u8s> T>
int to_int(const T& t) {
if (t.at(0) > '9') {
auto r = t. template toInt<int, true, 16, false>();
Expand Down
Loading

0 comments on commit daa76bb

Please sign in to comment.