
18 Jun
2012
18 Jun
'12
11:03 p.m.
On Mon, Jun 18, 2012 at 3:53 PM, Bas van Dijk
Slicing is done by directly updating the pointer in the ForeignPtr:
{-# INLINE basicUnsafeSlice #-} basicUnsafeSlice i n (Vector _ fp) = Vector n (updPtr (`advancePtr` i) fp)
{-# INLINE updPtr #-} updPtr :: (Ptr a -> Ptr a) -> ForeignPtr a -> ForeignPtr a updPtr f (ForeignPtr p c) = case f (Ptr p) of { Ptr q -> ForeignPtr q c }
This saves an Int.
(This is off-topic as far as the proposal.) ByteString has an extra Ptr field so that accessing the data is fast, given that ForeignPtrs can't be unpacked. -- Johan