Browse Source

perf: read the request body directly in the memory allocated by PHP

Kévin Dunglas 1 year ago
parent
commit
a4938102e1
1 changed files with 1 additions and 5 deletions
  1. 1 5
      frankenphp.go

+ 1 - 5
frankenphp.go

@@ -599,7 +599,7 @@ func go_sapi_flush(rh C.uintptr_t) bool {
 func go_read_post(rh C.uintptr_t, cBuf *C.char, countBytes C.size_t) (readBytes C.size_t) {
 	r := cgo.Handle(rh).Value().(*http.Request)
 
-	p := make([]byte, countBytes)
+	p := unsafe.Slice((*byte)(unsafe.Pointer(cBuf)), countBytes)
 	var err error
 	for readBytes < countBytes && err == nil {
 		var n int
@@ -613,10 +613,6 @@ func go_read_post(rh C.uintptr_t, cBuf *C.char, countBytes C.size_t) (readBytes
 		fc.Logger.Error("error while reading the request body", zap.Error(err))
 	}
 
-	if readBytes != 0 {
-		C.memcpy(unsafe.Pointer(cBuf), unsafe.Pointer(&p[0]), C.size_t(readBytes))
-	}
-
 	return
 }