Efficient in-memory encoding for Unicode strings