[AccessD] Swap two elements in an array

Stuart McLachlan stuart at lexacorp.com.pg
Thu Aug 25 23:30:04 CDT 2022


On 26 Aug 2022 at 15:58, Paul Wolstenholme wrote:

> I would expect this version is likely to be compiled as faster code
> (fewer parameters, fewer array lookups and the possibility of those
> array lookups being based partially or wholly on expressions the
> compiler can evaluate to constants).  It also allows the function to
> be used with any pair of variables - not just array elements.

You want faster code?
Avoid the overhead of casting to/from variants altogether :)

Function iSwap(x As Long, y As Long) As Boolean
    'swap integral variables
    Dim t As Long
    t = x
    x = y
    y = t
    iSwap = True
End Function
Function fSwap(x As Long, y As Long) As Boolean
    'Swap float  variables
    Dim t As Long
    t = x
    x = y
    y = t
    iSwap = True
End Function
Function sSwap(x As String, y As String) As Boolean
    'swap string variables
    Dim t As String
    t = x
    x = y
    y = t
    iSwap = True
End Function



More information about the AccessD mailing list