Avoid resolving loaded request entries twice
This commit is contained in:
+12
-18
@@ -724,26 +724,20 @@ void unit_render(String file_name) { unit_render(file_name, *context); }
|
||||
|
||||
extern "C" {
|
||||
|
||||
// Host calls this to invoke the request's entry unit through a named handler
|
||||
// ("render"/"cli"/"websocket"/"serve_http:named"). It is the same resolve +
|
||||
// ONCE() + dispatch path as components — the entry handler is just another
|
||||
// export. The host pre-checks the export exists, so a missing slot is a no-op.
|
||||
void uce_wasm_invoke_entry(const char* path, size_t path_len, const char* handler, size_t handler_len)
|
||||
// The host has already loaded the request's entry unit and can place its
|
||||
// exports directly in the shared table. This avoids resolving that same unit
|
||||
// back through a hostcall while preserving per-request ONCE deduplication.
|
||||
void uce_wasm_invoke_loaded_entry(s32 handler_slot, s32 once_slot)
|
||||
{
|
||||
// the host always runs uce_wasm_core_init + apply_context before this
|
||||
String file_name(path, path_len);
|
||||
String handler_name(handler, handler_len);
|
||||
String resolved;
|
||||
s32 slot = wasm_resolve_target(trim(file_name), handler_name, &resolved);
|
||||
if(!slot)
|
||||
return;
|
||||
wasm_run_once(resolved, *context);
|
||||
String previous_unit = context->resources.current_unit_file;
|
||||
if(resolved != "")
|
||||
context->resources.current_unit_file = resolved;
|
||||
WasmRequestHandler handler_fn = (WasmRequestHandler)(uintptr_t)slot;
|
||||
String resolved = context->resources.current_unit_file;
|
||||
if(once_slot && resolved != "" && context->once_units.find(resolved) == context->once_units.end())
|
||||
{
|
||||
context->once_units.insert(resolved);
|
||||
WasmRequestHandler once_handler = (WasmRequestHandler)(uintptr_t)once_slot;
|
||||
once_handler(*context);
|
||||
}
|
||||
WasmRequestHandler handler_fn = (WasmRequestHandler)(uintptr_t)handler_slot;
|
||||
handler_fn(*context);
|
||||
context->resources.current_unit_file = previous_unit;
|
||||
}
|
||||
|
||||
void* uce_alloc(size_t len)
|
||||
|
||||
Reference in New Issue
Block a user