Skip to content

Commit

Permalink
apply just an optimization (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
withinboredom authored Dec 30, 2023
1 parent 9b9957f commit 2055142
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions frankenphp.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,8 +594,6 @@ void frankenphp_register_bulk_variables(char *known_variables[27],
free(dynamic_variables[i]);
free(dynamic_variables[i + 1]);
}

free(dynamic_variables);
}

static void frankenphp_register_variables(zval *track_vars_array) {
Expand Down
10 changes: 7 additions & 3 deletions frankenphp.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,8 +546,7 @@ func go_register_variables(rh C.uintptr_t, trackVarsArray *C.zval) {
fc := r.Context().Value(contextKey).(*FrankenPHPContext)

le := (len(fc.env) + len(r.Header)) * 2
dynamicVariablesArr := (**C.char)(C.malloc(C.size_t(le) * C.size_t(unsafe.Sizeof((*C.char)(nil)))))
dynamicVariables := unsafe.Slice(dynamicVariablesArr, le)
dynamicVariables := make([]*C.char, le)

var i int
// Add all HTTP headers to env variables
Expand All @@ -572,8 +571,13 @@ func go_register_variables(rh C.uintptr_t, trackVarsArray *C.zval) {
i++
}

var dynamicVariablesPtr **C.char = nil
if le > 0 {
dynamicVariablesPtr = &dynamicVariables[0]
}

knownVariables := computeKnownVariables(r)
C.frankenphp_register_bulk_variables(&knownVariables[0], dynamicVariablesArr, C.size_t(le), trackVarsArray)
C.frankenphp_register_bulk_variables(&knownVariables[0], dynamicVariablesPtr, C.size_t(le), trackVarsArray)

fc.env = nil
}
Expand Down

0 comments on commit 2055142

Please sign in to comment.