String#gsub and String#sub should return original string if no substitution(s) have been made
Currently if one were to call
'Hello World'.gsub(/[<&>]/, html_entities_hash) , a copy of 'Hello World' is allocated and returned. If such a call were to occur inside a loop, then that would cause numerous copies to be allocated simply from an attempt at substitution.
'Hello World'.sub(/\d+/, 'x')
Opting for the destructive alternatives is not possible since the original string should remain unchanged in all cases.
IMO, it'd be great to have the original string returned if substitution(s) couldn't be made.