Isn't it obvious that all improvements you propose end up worse? toUTFz converts to a zero-terminated UTF string, and that's what it returns.