Enhance performance of decode_string function.