Skip to content

Commit

Permalink
chore: remove regex usage from the header file
Browse files Browse the repository at this point in the history
  • Loading branch information
Samy-33 committed Jan 14, 2025
1 parent 5a9a0f4 commit 4ca9842
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion compiler+runtime/include/cpp/jank/c_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions compiler+runtime/include/cpp/jank/runtime/core/munge.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
#pragma once

#include <regex>
#include <jank/runtime/object.hpp>

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);
Expand Down
2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/c_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/jit/processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<llvm::orc::SymbolsCouldNotBeRemoved>())
{
Expand Down
2 changes: 1 addition & 1 deletion compiler+runtime/src/cpp/jank/runtime/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, "_"),
Expand Down
7 changes: 4 additions & 3 deletions compiler+runtime/src/cpp/jank/runtime/core/munge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
8 changes: 2 additions & 6 deletions compiler+runtime/src/cpp/jank/runtime/core/seq.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <jank/runtime/behavior/conjable.hpp>
#include <jank/runtime/behavior/countable.hpp>
#include <jank/runtime/behavior/seqable.hpp>
#include <jank/runtime/behavior/set_like.hpp>
#include <jank/runtime/behavior/sequential.hpp>
#include <jank/runtime/behavior/collection_like.hpp>
#include <jank/runtime/behavior/transientable.hpp>
Expand Down Expand Up @@ -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<S>)
{
return typed_s->contains(key);
}
if constexpr(std::same_as<S, obj::persistent_hash_set>
|| std::same_as<S, obj::persistent_sorted_set>)
if constexpr(behavior::associatively_readable<S> || behavior::set_like<S>)
{
return typed_s->contains(key);
}
Expand Down
4 changes: 2 additions & 2 deletions compiler+runtime/src/cpp/jank/runtime/module/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 4ca9842

Please sign in to comment.