ListReverse

From Second Life Wiki
Revision as of 14:20, 22 January 2015 by ObviousAltIsObvious Resident (talk | contribs) (<lsl> tag to <source>)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

User-Defined Function: list uListReverse( list vLstSrc );

Returns a list that is vLstSrc with the elements in reverse order

  • vLstSrc: source list to reverse


Smaller Code:

  • LSO: 156 Bytes
  • MONO: 512 Bytes
list uListReverse( list vLstSrc ){
    integer vIntCnt = (vLstSrc != []);
    while (vIntCnt){
        vLstSrc += llList2List( vLstSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
        vLstSrc = llDeleteSubList( vLstSrc, vIntCnt, vIntCnt );
    }
    return vLstSrc;
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Faster Code:

  • LSO: 160 Bytes
  • MONO: 512 Bytes
list uListReverse( list vLstSrc ){
    integer vIntCnt = (vLstSrc != []);
    while (vIntCnt){
        vLstSrc += llList2List( vLstSrc, (vIntCnt = ~-vIntCnt), vIntCnt );
    }
    return llList2List( vLstSrc, (vLstSrc != []) >> 1, -1 );
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Caveats

  • The "Faster" version doubles the list size internally, and is more likely to cause a stack/heap collision(script crash) with large lists and/or limited free memory

Notes