envoy-mobile icon indicating copy to clipboard operation
envoy-mobile copied to clipboard

core: pass strings as references

Open Augustyniak opened this issue 2 years ago • 1 comments

Description: Passing these strings as references may help us to avoid doing copying during initialization. Risk Level: Low Testing: Manual Docs Changes: N/A Release Notes: N/A

Signed-off-by: Rafal Augustyniak [email protected]

Augustyniak avatar Aug 19 '22 21:08 Augustyniak

You need to be absolutely sure of the lifetime of these strings if you're going to pass them as references. main is used to spawn a new thread, and the call stack from run will return long before it's complete. Unless these are managed safely somewhere, I don't see how this can be safe to do. On the other hand, when passing as raw strings, there's a chance the compiler/optimizer can still manage the string by default relatively efficiently and avoid some unnecessary copies (the standard mentions a few cases copy elision is allowed - that may be a stretch though, but you could of course examine the compiled code to see).

goaway avatar Aug 24 '22 18:08 goaway