On 19/06/2012, at 00:03, Johan Tibell wrote:

> On Mon, Jun 18, 2012 at 3:53 PM, Bas van Dijk <v.dijk....@gmail.com> wrote:
>> 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.

ForeignPtrs can be unpacked, just not manually (which is a GHC bug, IMO, I 
should report it):

data Vector a = Vector {-# UNPACK #-} !Int
                       {-# UNPACK #-} !(ForeignPtr a)

ByteString just has some room for optimisation here ;-)

Roman



_______________________________________________
Haskell-platform mailing list
Haskell-platform@projects.haskell.org
http://projects.haskell.org/cgi-bin/mailman/listinfo/haskell-platform

Reply via email to