I'm writing an open source library for Rust, and would like to serve an API that writes &'static str wrapped with double quotation mark (") into memory. Here is a simplified code:
Assembly output says it writes double quotation mark first, write contents, and then double quotation mark again.
I implemented the exactly same operation in C, but clang optimize this as I expected.
What surprised me more is, if I removed the test2 function from above Rust code, LLVM properly optimize the operations.
Could you tell me why things happen, and how can I make things work?
After some tests, looks like that using a &str as argument for write_unquoted allows it to be better optimized because it guarantees that src and dst aren't overlapped, however this probably comes back and bite us when it is inlined in test1 and test2.