Use StringRef to avoid copies and simplify code.