string.split(str) generates an Array even if string doesn't contain str. Therefore, to avoid allocating an intermediate array unnecessarily, split given string only if string contains str.
string.sub(str, ...) duplicates string even if string doesn't contain str. Therefore, opt to use string.sub!(str, ...) instead.
Summary
string.split(str)
generates an Array even ifstring
doesn't containstr
. Therefore, to avoid allocating an intermediate array unnecessarily,split
givenstring
only ifstring
containsstr
.string.sub(str, ...)
duplicatesstring
even ifstring
doesn't containstr
. Therefore, opt to usestring.sub!(str, ...)
instead.