From 4ca98424d0ec2ebf6ce076933eaa7ed4a7968802 Mon Sep 17 00:00:00 2001 From: Saket Patel Date: Tue, 14 Jan 2025 22:33:24 +0530 Subject: [PATCH] chore: remove regex usage from the header file --- compiler+runtime/include/cpp/jank/c_api.h | 2 +- compiler+runtime/include/cpp/jank/runtime/core/munge.hpp | 3 +-- compiler+runtime/src/cpp/jank/c_api.cpp | 2 +- compiler+runtime/src/cpp/jank/jit/processor.cpp | 2 +- compiler+runtime/src/cpp/jank/runtime/context.cpp | 2 +- compiler+runtime/src/cpp/jank/runtime/core/munge.cpp | 7 ++++--- compiler+runtime/src/cpp/jank/runtime/core/seq.cpp | 8 ++------ compiler+runtime/src/cpp/jank/runtime/module/loader.cpp | 4 ++-- 8 files changed, 13 insertions(+), 17 deletions(-) diff --git a/compiler+runtime/include/cpp/jank/c_api.h b/compiler+runtime/include/cpp/jank/c_api.h index 2bceb5f26..51c4a02b2 100644 --- a/compiler+runtime/include/cpp/jank/c_api.h +++ b/compiler+runtime/include/cpp/jank/c_api.h @@ -24,7 +24,7 @@ extern "C" jank_object_ptr jank_eval(jank_object_ptr s); jank_object_ptr jank_read_string(jank_object_ptr s); - void jank_ns_set_symbol_counter(char const * const ns, uint64_t count); + void jank_ns_set_symbol_counter(char const * const ns, uint64_t const count); jank_object_ptr jank_var_intern(jank_object_ptr ns, jank_object_ptr name); jank_object_ptr jank_var_bind_root(jank_object_ptr var, jank_object_ptr val); diff --git a/compiler+runtime/include/cpp/jank/runtime/core/munge.hpp b/compiler+runtime/include/cpp/jank/runtime/core/munge.hpp index a6bf6a095..01072ac0e 100644 --- a/compiler+runtime/include/cpp/jank/runtime/core/munge.hpp +++ b/compiler+runtime/include/cpp/jank/runtime/core/munge.hpp @@ -1,13 +1,12 @@ #pragma once -#include #include namespace jank::runtime { native_persistent_string munge(native_persistent_string const &o); native_persistent_string munge_extra(native_persistent_string const &o, - std::regex const &search, + native_persistent_string const &search, char const * const replace); object_ptr munge(object_ptr o); native_persistent_string demunge(native_persistent_string const &o); diff --git a/compiler+runtime/src/cpp/jank/c_api.cpp b/compiler+runtime/src/cpp/jank/c_api.cpp index c1adde533..9ba428744 100644 --- a/compiler+runtime/src/cpp/jank/c_api.cpp +++ b/compiler+runtime/src/cpp/jank/c_api.cpp @@ -75,7 +75,7 @@ extern "C" return __rt_ctx->read_string(s_obj->data); } - void jank_ns_set_symbol_counter(char const * const ns, uint64_t count) + void jank_ns_set_symbol_counter(char const * const ns, uint64_t const count) { auto const ns_obj(__rt_ctx->intern_ns(ns)); ns_obj->symbol_counter.store(count); diff --git a/compiler+runtime/src/cpp/jank/jit/processor.cpp b/compiler+runtime/src/cpp/jank/jit/processor.cpp index 05e421e1f..e79a107dc 100644 --- a/compiler+runtime/src/cpp/jank/jit/processor.cpp +++ b/compiler+runtime/src/cpp/jank/jit/processor.cpp @@ -191,7 +191,7 @@ namespace jank::jit auto &ee{ interpreter->getExecutionEngine().get() }; llvm::orc::SymbolNameSet to_remove{}; to_remove.insert(ee.mangleAndIntern(name.c_str())); - auto const error = ee.getMainJITDylib().remove(to_remove); + auto const error{ ee.getMainJITDylib().remove(to_remove) }; if(error.isA()) { diff --git a/compiler+runtime/src/cpp/jank/runtime/context.cpp b/compiler+runtime/src/cpp/jank/runtime/context.cpp index cc9da2642..a1b95da62 100644 --- a/compiler+runtime/src/cpp/jank/runtime/context.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/context.cpp @@ -323,7 +323,7 @@ namespace jank::runtime native_persistent_string context::unique_string(native_persistent_string_view const &prefix) { - static std::regex const dot{ "\\." }; + static native_persistent_string const dot{ "\\." }; auto const ns{ current_ns() }; return fmt::format(FMT_COMPILE("{}-{}-{}"), runtime::munge_extra(ns->name->get_name(), dot, "_"), diff --git a/compiler+runtime/src/cpp/jank/runtime/core/munge.cpp b/compiler+runtime/src/cpp/jank/runtime/core/munge.cpp index 8d8c52950..13fd80291 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/munge.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/munge.cpp @@ -286,11 +286,12 @@ namespace jank::runtime } native_persistent_string munge_extra(native_persistent_string const &o, - std::regex const &search, + native_persistent_string const &search, char const * const replace) { - std::string ret{ munge(o) }; - return std::regex_replace(ret, search, replace); + native_transient_string const ret{ munge(o) }; + std::regex const search_regex{ search.c_str() }; + return std::regex_replace(ret, search_regex, replace); } /* TODO: Support symbols and other data; Clojure takes in anything and passes it through str. */ diff --git a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp index e64439a25..74275d8ca 100644 --- a/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/core/seq.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -670,12 +671,7 @@ namespace jank::runtime [&](auto const typed_s) -> native_bool { using S = typename decltype(typed_s)::value_type; - if constexpr(behavior::associatively_readable) - { - return typed_s->contains(key); - } - if constexpr(std::same_as - || std::same_as) + if constexpr(behavior::associatively_readable || behavior::set_like) { return typed_s->contains(key); } diff --git a/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp b/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp index 12d339b85..f742b32d2 100644 --- a/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp +++ b/compiler+runtime/src/cpp/jank/runtime/module/loader.cpp @@ -38,13 +38,13 @@ namespace jank::runtime::module native_persistent_string module_to_path(native_persistent_string_view const &module) { - static std::regex const dot{ "\\." }; + static native_persistent_string const dot{ "\\." }; return runtime::munge_extra(module, dot, "/"); } native_persistent_string module_to_load_function(native_persistent_string_view const &module) { - static std::regex const dot{ "\\." }; + static native_persistent_string const dot{ "\\." }; std::string ret{ runtime::munge_extra(module, dot, "_") }; return fmt::format("jank_load_{}", ret);