Bug #86519
closedString "beginsWith" and "endsWith" uses strpos / strrpos which will needlessly scan the entire haystack string, wasting performance
0%
Description
There is a logical issue with the string-begins-with and -ends-with testing in StringUtility:
Logic dictates that a test for "begins with" will not need to scan a string beyond the number of characters contained in the needle. Likewise, to test for "ends with" you will not need to scan further than needle-length characters from the end of the haystack.
The use of strpos and strrpos defeats this logic by always scanning the entire string to end until any occurrence is found or none, then comparing the position at which the needle was found. A much, much more efficient choice of strategy would be to substring the haystack and use strncmp to immediately compare if the exact targeted number of bytes from start/end of haystack matches the needle.