Changeset 2627 for src/Pugs/Types

Show
Ignore:
Timestamp:
05/02/05 17:47:01 (4 years ago)
Author:
autrijus
svk:copy_cache_prev:
4152
Message:

* much faster pop/push implementation

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Types/Array.hs

    r2624 r2627  
    149149            let svList = IntMap.elems avMap in 
    150150            IntMap.fromAscList ([0..] `zip` ((map lazyScalar vals) ++ svList)) 
     151    array_pop av = do 
     152        avMap <- liftSTM $ readTVar av 
     153        if IntMap.null avMap 
     154            then return undef 
     155            else do 
     156                let idx = IntMap.size avMap - 1 
     157                liftSTM $ writeTVar av $ IntMap.delete idx avMap 
     158                readIVar . fromJust $ IntMap.lookup idx avMap 
     159    array_push av vals = do 
     160        liftSTM $ modifyTVar av $ \avMap -> 
     161            let svList = IntMap.elems avMap in 
     162            IntMap.fromAscList ([0..] `zip` (svList ++ (map lazyScalar vals))) 
    151163    array_extendSize _ 0 = return () 
    152164    array_extendSize av sz = do