More efficient implementation of generalizeStringSlice