diff options
author | Valery Piashchynski <[email protected]> | 2021-02-05 23:10:50 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-02-05 23:10:50 +0300 |
commit | 11b357c4457dfcbc1ef79478c200b794b5486b13 (patch) | |
tree | 29b512baf4d6a8ef79e19a0de3a9e642871b6d4e /pkg/pool/static_pool.go | |
parent | 6c8cf12de734f01a0f0cdc4d2b55973cc8d1ddf1 (diff) |
Faster toString convertation (only for the english)
Diffstat (limited to 'pkg/pool/static_pool.go')
-rwxr-xr-x | pkg/pool/static_pool.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/pool/static_pool.go b/pkg/pool/static_pool.go index 23f24e27..dd52f313 100755 --- a/pkg/pool/static_pool.go +++ b/pkg/pool/static_pool.go @@ -4,6 +4,7 @@ import ( "context" "os/exec" "time" + "unsafe" "github.com/spiral/errors" "github.com/spiral/roadrunner/v2/pkg/events" @@ -148,8 +149,8 @@ func (sp *StaticPool) Exec(p payload.Payload) (payload.Payload, error) { } // worker want's to be terminated - // TODO careful with string(rsp.Context) - if len(rsp.Body) == 0 && string(rsp.Context) == StopRequest { + // TODO careful with toString(rsp.Context) + if len(rsp.Body) == 0 && toString(rsp.Context) == StopRequest { sp.stopWorker(w) return sp.Exec(p) } @@ -178,7 +179,7 @@ func (sp *StaticPool) ExecWithContext(ctx context.Context, p payload.Payload) (p } // worker want's to be terminated - if len(rsp.Body) == 0 && string(rsp.Context) == StopRequest { + if len(rsp.Body) == 0 && toString(rsp.Context) == StopRequest { sp.stopWorker(w) return sp.ExecWithContext(ctx, p) } @@ -323,3 +324,8 @@ func (sp *StaticPool) allocateWorkers(numWorkers uint64) ([]worker.SyncWorker, e } return workers, nil } + +// unsafe, but lightning fast []byte to string conversion +func toString(data []byte) string { + return *(*string)(unsafe.Pointer(&data)) +} |