3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-07 09:55:19 +00:00

reduce memory allocs in params

This commit is contained in:
Nuno Lopes 2023-12-21 23:27:09 +00:00
parent ae1d9270b5
commit 766f5f04c0
2 changed files with 15 additions and 19 deletions

View file

@ -99,25 +99,24 @@ struct param_descrs::imp {
return CPK_INVALID; return CPK_INVALID;
} }
bool split_name(symbol const& name, symbol & prefix, symbol & suffix) const { bool split_name(symbol const& name, std::string_view & prefix, symbol & suffix) const {
if (name.is_numerical()) return false; if (name.is_numerical()) return false;
char const* str = name.bare_str(); char const* str = name.bare_str();
char const* period = strchr(str,'.'); char const* period = strchr(str,'.');
if (!period) return false; if (!period) return false;
svector<char> prefix_((unsigned)(period-str), str); prefix = std::string_view(str, period - str);
prefix_.push_back(0);
prefix = symbol(prefix_.data());
suffix = symbol(period + 1); suffix = symbol(period + 1);
return true; return true;
} }
param_kind get_kind_in_module(symbol & name) const { param_kind get_kind_in_module(symbol & name) const {
param_kind k = get_kind(name); param_kind k = get_kind(name);
symbol prefix, suffix; std::string_view prefix;
symbol suffix;
if (k == CPK_INVALID && split_name(name, prefix, suffix)) { if (k == CPK_INVALID && split_name(name, prefix, suffix)) {
k = get_kind(suffix); k = get_kind(suffix);
if (k != CPK_INVALID) { if (k != CPK_INVALID) {
if (symbol(get_module(suffix)) == prefix) { if (get_module(suffix) == prefix) {
name = suffix; name = suffix;
} }
else { else {
@ -170,8 +169,8 @@ struct param_descrs::imp {
if (names.empty()) if (names.empty())
return; return;
if (markdown) { if (markdown) {
out << " Parameter | Type | Description | Default\n"; out << " Parameter | Type | Description | Default\n"
out << " ----------|------|-------------|--------\n"; " ----------|------|-------------|--------\n";
} }
for (symbol const& name : names) { for (symbol const& name : names) {
for (unsigned i = 0; i < indent; i++) out << " "; for (unsigned i = 0; i < indent; i++) out << " ";
@ -197,16 +196,14 @@ struct param_descrs::imp {
else else
out << " (" << d.m_kind << ")"; out << " (" << d.m_kind << ")";
if (markdown) { if (markdown) {
out << " | "; out << " | ";
std::string desc; for (auto ch : std::string_view(d.m_descr)) {
for (auto ch : std::string(d.m_descr)) {
switch (ch) { switch (ch) {
case '<': desc += "&lt;"; break; case '<': out << "&lt;"; break;
case '>': desc += "&gt;"; break; case '>': out << "&gt;"; break;
default: desc.push_back(ch); default: out << ch; break;
} }
} }
out << " " << desc;
} }
else if (include_descr) else if (include_descr)
out << " " << d.m_descr; out << " " << d.m_descr;
@ -549,8 +546,7 @@ params_ref::~params_ref() {
m_params->dec_ref(); m_params->dec_ref();
} }
params_ref::params_ref(params_ref const & p): params_ref::params_ref(params_ref const & p) {
m_params(nullptr) {
set(p); set(p);
} }

View file

@ -32,12 +32,12 @@ class param_descrs;
class params_ref { class params_ref {
static params_ref g_empty_params_ref; static params_ref g_empty_params_ref;
params * m_params; params * m_params = nullptr;
void init(); void init();
void copy_core(params const * p); void copy_core(params const * p);
void set(params_ref const& p); void set(params_ref const& p);
public: public:
params_ref():m_params(nullptr) {} params_ref() = default;
params_ref(params_ref const & p); params_ref(params_ref const & p);
~params_ref(); ~params_ref();