Option Explicit


Public Function Replicate14(ByVal lNumber As Long, ByRef sPattern As String) As String ' by Marzo Sette Torres Junior, marzojr@taskmail.com.br, 20020621 ' remotely based on Replicate12, by myself ' steals a few ideas from Replicate13, by Paul, wpsjr1@syix.com, 20020610 ' requires FastString type library Dim lPointer&, lLen&, lPtr&, lDst& lPointer = LenB(sPattern) lLen = lNumber * lPointer If lLen > 0& Then If lPointer > 3& Then 'borrowing a good idea by Paul: lPtr = FastString.SysAllocStringLenPtr(ByVal 0&, ByVal lLen) lDst = lPtr + lPointer 'First copy: FastString.VB6.vbaCopyBytesStr lPointer, ByVal lPtr, sPattern 'We find the highest bit set and copy a number of times equal to 'the position of this bit. At each copy, we double the length of 'what we copy. Note that only the first 8 copies are done using 'vbaCopyBytes, while the rest use RtlMoveMemory; in my tests, 'this resulted in a net speed gain for call 2. It appears that 'RtlMoveMemory is faster than vbaCopyBytes for large data to copy, 'while the converse is true for small data. Not much to see, this 'works the same way as the While...Wend loops on Replicate12, but 'since the maximum number of copies is 30, the loop is removed. If lNumber And &H7FFFFF00 Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& If lNumber And &H7FFF0000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& If lNumber And &H7F000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& If lNumber And &H40000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H20000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H10000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H8000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H4000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H2000000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& 'ElseIf lNumber And &H1000000 Then End If Else If lNumber And &H800000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H400000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H200000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H100000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H80000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H40000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H20000 Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& 'ElseIf lNumber And &H10000 Then End If End If Else If lNumber And &H8000& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H4000& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H2000& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H1000& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H800& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H400& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& ElseIf lNumber And &H200& Then FastString.RtlMoveMemory ByVal lDst, ByVal lPtr, ByVal lPointer lDst = lDst + lPointer: lPointer = lPointer * &H2& 'ElseIf lNumber And &H100& Then End If End If Else If lNumber And &H80& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr ElseIf lNumber And &H40& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr ElseIf lNumber And &H20& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr ElseIf lNumber And &H10& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr ElseIf lNumber And &H8& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr ElseIf lNumber And &H4& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr lDst = lDst + lPointer: lPointer = lPointer * &H2& FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr ElseIf lNumber And &H2& Then FastString.VB6.vbaCopyBytes lPointer, ByVal lDst, ByVal lPtr Else FastString.VB6.vbaCopyBytes 4&, Replicate14, lPtr Exit Function End If lDst = lDst + lPointer: lPointer = lPointer * &H2& End If 'Find what still needs to be copied: lLen = lLen - lPointer FastString.VB6.vbaCopyBytes lLen, ByVal lDst, ByVal lPtr 'borrowing a good idea by Paul: FastString.VB6.vbaCopyBytes 4&, Replicate14, lPtr Else Replicate14 = String$(lNumber, sPattern) End If End If End Function