Bug #15895

Updated by ashmaroli (Ashwin Maroli) over 3 years ago

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. 

 Likewise for `'Hello World'.sub(/\d+/, 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.