get rid of some unnecessary string allocs
parent
d3ec4a47dd
commit
b534a6d9af
|
@ -183,7 +183,7 @@ void cs_init_lib_list(cs_state &gcs) {
|
|||
if (offset > 0) {
|
||||
list_find_item(p);
|
||||
}
|
||||
res.set_str(cs_string{p.input});
|
||||
res.set_str(p.input);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -207,7 +207,7 @@ void cs_init_lib_list(cs_state &gcs) {
|
|||
int n = -1;
|
||||
for (cs_list_parse_state p{args[1].get_str()}; list_parse(p, cs);) {
|
||||
++n;
|
||||
idv.set_str(cs_string{p.item});
|
||||
idv.set_str(p.item);
|
||||
idv.push();
|
||||
if (cs.run_bool(body)) {
|
||||
res.set_int(cs_int(n));
|
||||
|
@ -226,7 +226,7 @@ void cs_init_lib_list(cs_state &gcs) {
|
|||
int n = -1;
|
||||
for (cs_list_parse_state p{args[1].get_str()}; list_parse(p, cs);) {
|
||||
++n;
|
||||
idv.set_str(cs_string{p.item});
|
||||
idv.set_str(p.item);
|
||||
idv.push();
|
||||
if (cs.run_bool(body)) {
|
||||
if (list_parse(p, cs)) {
|
||||
|
|
|
@ -52,7 +52,8 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
});
|
||||
|
||||
cs.new_command("codestr", "i", [](auto &, auto args, auto &res) {
|
||||
res.set_str(cs_string(1, char(args[0].get_int())));
|
||||
char const p[2] = { char(args[0].get_int()), '\0' };
|
||||
res.set_str(ostd::string_range{static_cast<char const *>(p)});
|
||||
});
|
||||
|
||||
cs.new_command("strlower", "s", [](auto &, auto args, auto &res) {
|
||||
|
@ -141,11 +142,11 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
cs_int start = args[1].get_int(), count = args[2].get_int();
|
||||
cs_int numargs = args[3].get_int();
|
||||
cs_int len = cs_int(s.size()), offset = std::clamp(start, cs_int(0), len);
|
||||
res.set_str(cs_string{
|
||||
res.set_str(ostd::string_range{
|
||||
&s[offset],
|
||||
(numargs >= 3)
|
||||
&s[offset] + ((numargs >= 3)
|
||||
? size_t(std::clamp(count, cs_int(0), len - offset))
|
||||
: size_t(len - offset)
|
||||
: size_t(len - offset))
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -181,7 +182,7 @@ void cs_init_lib_string(cs_state &cs) {
|
|||
}
|
||||
cs_string buf;
|
||||
if (!oldval.size()) {
|
||||
res.set_str(cs_string{s});
|
||||
res.set_str(s);
|
||||
return;
|
||||
}
|
||||
for (size_t i = 0;; ++i) {
|
||||
|
|
Loading…
Reference in New Issue