Reuse core host definitions across requests

This commit is contained in:
udo
2026-07-18 00:55:29 +00:00
parent 1ebf94b135
commit 6e4ef8ed7a
8 changed files with 212 additions and 56 deletions
+40 -4
View File
@@ -652,7 +652,7 @@ void DValue::set_bool(bool b)
_list_mode = false;
}
void DValue::set(DValue source)
void DValue::set(const DValue& source)
{
DValue* target = reference_target();
if(target)
@@ -691,6 +691,42 @@ void DValue::set(DValue source)
}
}
void DValue::set(DValue&& source)
{
DValue* target = reference_target();
if(target)
{
target->set(std::move(source));
return;
}
set_type(source.type);
switch(type)
{
case('S'):
_String = std::move(source._String);
_list_mode = false;
break;
case('F'):
_float = source._float;
_list_mode = false;
break;
case('B'):
_bool = source._bool;
_list_mode = false;
break;
case('M'):
_map = std::move(source._map);
_array_index = source._array_index;
_list_mode = source._list_mode;
break;
case('P'):
case('R'):
_ptr = source._ptr;
_list_mode = false;
break;
}
}
void DValue::set(StringMap source)
{
DValue* target = reference_target();
@@ -782,7 +818,7 @@ DValue& DValue::operator [] (String s) {
void DValue::operator = (String v) { set(v); }
void DValue::operator = (f64 v) { set(v); }
void DValue::operator = (void* v) { set(v); }
void DValue::operator = (DValue v) { set(v); }
void DValue::operator = (DValue v) { set(std::move(v)); }
void DValue::operator = (StringMap v) { set(v); }
void DValue::push(const DValue& child)
@@ -1076,7 +1112,7 @@ bool ucb_decode_node(const String& src, size_t& offset, DValue& out, String& err
DValue child;
if(!ucb_decode_node(src, offset, child, error, depth + 1))
return(false);
out[key] = child;
out[key] = std::move(child);
}
return(true);
}
@@ -1126,7 +1162,7 @@ bool ucb_decode(const String& encoded, DValue& out, String* error_out)
DValue decoded;
if(ucb_decode_node(encoded, offset, decoded, error) && offset == encoded.size())
{
out = decoded;
out = std::move(decoded);
if(error_out)
*error_out = "";
return(true);
+5 -1
View File
@@ -8,6 +8,9 @@ String json_escape(String s, char quote_char = '"');
// JSON-decoded values, and metadata trees can be consumed without repetitive
// manual parsing at each call site.
struct DValue {
DValue() = default;
DValue(const DValue&) = default;
DValue(DValue&&) = default;
char type = 'S';
@@ -49,7 +52,8 @@ struct DValue {
void set(void* p);
void set(f64 f);
void set_bool(bool b);
void set(DValue source);
void set(const DValue& source);
void set(DValue&& source);
void set(StringMap source);
void set_array();
void set_reference(DValue* target);