move strref impl to cs_util
parent
08212df80f
commit
5a4cccf194
|
@ -286,6 +286,51 @@ char *cs_strman::alloc_buf(std::size_t len) const {
|
||||||
return strp;
|
return strp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* strref */
|
||||||
|
|
||||||
|
cs_strref::cs_strref(cs_shared_state &cs, ostd::string_range str):
|
||||||
|
p_state{&cs}
|
||||||
|
{
|
||||||
|
p_str = cs.strman->add(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
cs_strref::cs_strref(cs_state &cs, ostd::string_range str):
|
||||||
|
p_state{cs.p_state}
|
||||||
|
{
|
||||||
|
p_str = p_state->strman->add(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
cs_strref::cs_strref(cs_strref const &ref): p_state{ref.p_state}, p_str{ref.p_str}
|
||||||
|
{
|
||||||
|
p_state->strman->ref(p_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this can be used by friends to do quick cs_strref creation */
|
||||||
|
cs_strref::cs_strref(char const *p, cs_shared_state &cs):
|
||||||
|
p_state{&cs}
|
||||||
|
{
|
||||||
|
p_str = p_state->strman->ref(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
cs_strref::~cs_strref() {
|
||||||
|
p_state->strman->unref(p_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
cs_strref &cs_strref::operator=(cs_strref const &ref) {
|
||||||
|
p_str = ref.p_str;
|
||||||
|
p_state = ref.p_state;
|
||||||
|
p_state->strman->ref(p_str);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
cs_strref::operator ostd::string_range() const {
|
||||||
|
return p_state->strman->get(p_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool cs_strref::operator==(cs_strref const &s) const {
|
||||||
|
return p_str == s.p_str;
|
||||||
|
}
|
||||||
|
|
||||||
namespace util {
|
namespace util {
|
||||||
OSTD_EXPORT ostd::string_range parse_string(
|
OSTD_EXPORT ostd::string_range parse_string(
|
||||||
cs_state &cs, ostd::string_range str, size_t &nlines
|
cs_state &cs, ostd::string_range str, size_t &nlines
|
||||||
|
|
43
src/cs_vm.cc
43
src/cs_vm.cc
|
@ -7,49 +7,6 @@
|
||||||
|
|
||||||
namespace cscript {
|
namespace cscript {
|
||||||
|
|
||||||
cs_strref::cs_strref(cs_shared_state &cs, ostd::string_range str):
|
|
||||||
p_state{&cs}
|
|
||||||
{
|
|
||||||
p_str = cs.strman->add(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
cs_strref::cs_strref(cs_state &cs, ostd::string_range str):
|
|
||||||
p_state{cs.p_state}
|
|
||||||
{
|
|
||||||
p_str = p_state->strman->add(str);
|
|
||||||
}
|
|
||||||
|
|
||||||
cs_strref::cs_strref(cs_strref const &ref): p_state{ref.p_state}, p_str{ref.p_str}
|
|
||||||
{
|
|
||||||
p_state->strman->ref(p_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* this can be used by friends to do quick cs_strref creation */
|
|
||||||
cs_strref::cs_strref(char const *p, cs_shared_state &cs):
|
|
||||||
p_state{&cs}
|
|
||||||
{
|
|
||||||
p_str = p_state->strman->ref(p);
|
|
||||||
}
|
|
||||||
|
|
||||||
cs_strref::~cs_strref() {
|
|
||||||
p_state->strman->unref(p_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
cs_strref &cs_strref::operator=(cs_strref const &ref) {
|
|
||||||
p_str = ref.p_str;
|
|
||||||
p_state = ref.p_state;
|
|
||||||
p_state->strman->ref(p_str);
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
cs_strref::operator ostd::string_range() const {
|
|
||||||
return p_state->strman->get(p_str);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool cs_strref::operator==(cs_strref const &s) const {
|
|
||||||
return p_str == s.p_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct cs_cmd_internal {
|
struct cs_cmd_internal {
|
||||||
static void call(
|
static void call(
|
||||||
cs_state &cs, cs_command *c, cs_value_r args, cs_value &ret
|
cs_state &cs, cs_command *c, cs_value_r args, cs_value &ret
|
||||||
|
|
Loading…
Reference in New Issue