﻿id	summary	reporter	owner	description	type	status	milestone	component	version	severity	resolution	keywords	cc
2172	_StringRepeat addition, increments performance with higher count	amarcruz		"Hi,
_StringRepeat is efficient, but its performance degrades with high values in its $iRepeatCount parameter.

To correct this, I'm proposing an amendment to _StringRepeat(), like this:


{{{
Func _StringRepeat($sString, $iRepeatCount)
	;==============================================
	; Local Constant/Variable Declaration Section
	;==============================================
	Local $sResult

	Select
		Case Not StringIsInt($iRepeatCount)
			SetError(1)
			Return """"
		Case StringLen($sString) < 1
			SetError(1)
			Return """"
		Case $iRepeatCount <= 0
			SetError(1)
			Return """"
		Case $iRepeatCount < 50   ;<=== changed, test for low count
			For $iCount = 1 To $iRepeatCount
				$sResult &= $sString
			Next

			Return $sResult
	EndSelect
	;=== added block, for $iRepeatCount >= 50, minimizes the steps
	While $iRepeatCount > 1
		If BitAND($iRepeatCount, 1) Then $sResult &= $sString
		$sString &= $sString
		$iRepeatCount = BitShift($iRepeatCount, 1)
	WEnd
	$sString &= $sResult
	Return $sString
	;=== end of added block
EndFunc   ;==>_StringRepeat
}}}

For example (In my PC):

_StringRepeat(""X"", 4000) takes 6461.5 ms, new version 228.6

Attached is functional and performance tests.
"	Feature Request	closed		Standard UDFs		None	Completed	udf, _stringrepeat, performance, modifications	
