Wolfgang Jeltsch pushed to branch wip/jeltsch/portable-bco-byte-array-serialization at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • libraries/ghci/GHCi/ResolvedBCO.hs
    ... ... @@ -152,34 +152,6 @@ instance Binary ResolvedBCO where
    152 152
           1 -> ResolvedStaticCon <$> get <*> get <*> get <*> get <*> get <*> get
    
    153 153
           _ -> error "Binary ResolvedBCO: invalid byte"
    
    154 154
     
    
    155
    -#if !defined(WORDS_BIGENDIAN)
    
    156
    -
    
    157
    --- | Serialize a 'BCOByteArray', writing the payload verbatim instead of
    
    158
    ---   serializing the individual elements. This must only be used when the host
    
    159
    ---   platform uses little endian and the bitsize of the element type of the
    
    160
    ---   array is the one that is used for the serialized form of elements.
    
    161
    -putBCOByteArrayDirectly :: Storable a => BCOByteArray a -> Put
    
    162
    -putBCOByteArrayDirectly @a (BCOByteArray byteArray#)
    
    163
    -  = putWord64le (fromIntegral size) <>
    
    164
    -    putBuilder (fromShortByteString (SBS byteArray#))
    
    165
    -  where
    
    166
    -
    
    167
    -  size :: Int
    
    168
    -  size = I# (sizeofByteArray# byteArray#) `div` sizeOf (undefined :: a)
    
    169
    -
    
    170
    --- | Deserialize a 'BCOByteArray', reading the payload verbatim instead of
    
    171
    ---   deserializing the individual elements. This must only be used when the host
    
    172
    ---   platform uses little endian and the bitsize of the element type of the
    
    173
    ---   array is the one that is used for the serialized form of elements.
    
    174
    -getBCOByteArrayDirectly :: Storable a => Get (BCOByteArray a)
    
    175
    -getBCOByteArrayDirectly @a = do
    
    176
    -  size <- fromIntegral <$> getWord64le :: Get Int
    
    177
    -  SBS byteArray# <- toShort <$> getByteString (size * sizeOf (undefined :: a))
    
    178
    -    -- Beware that there is no overflow check for the byte count computation.
    
    179
    -  return (BCOByteArray byteArray#)
    
    180
    -
    
    181
    -#endif
    
    182
    -
    
    183 155
     #if defined(WORDS_BIGENDIAN) || SIZEOF_HSWORD == 4
    
    184 156
     
    
    185 157
     -- | Serialize a 'BCOByteArray', not writing the payload verbatim but
    
    ... ... @@ -215,6 +187,34 @@ getBCOByteArrayPortably getElement = do
    215 187
     
    
    216 188
     #endif
    
    217 189
     
    
    190
    +#if !defined(WORDS_BIGENDIAN)
    
    191
    +
    
    192
    +-- | Serialize a 'BCOByteArray', writing the payload verbatim instead of
    
    193
    +--   serializing the individual elements. This must only be used when the host
    
    194
    +--   platform uses little endian and the bitsize of the element type of the
    
    195
    +--   array is the one that is used for the serialized form of elements.
    
    196
    +putBCOByteArrayDirectly :: Storable a => BCOByteArray a -> Put
    
    197
    +putBCOByteArrayDirectly @a (BCOByteArray byteArray#)
    
    198
    +  = putWord64le (fromIntegral size) <>
    
    199
    +    putBuilder (fromShortByteString (SBS byteArray#))
    
    200
    +  where
    
    201
    +
    
    202
    +  size :: Int
    
    203
    +  size = I# (sizeofByteArray# byteArray#) `div` sizeOf (undefined :: a)
    
    204
    +
    
    205
    +-- | Deserialize a 'BCOByteArray', reading the payload verbatim instead of
    
    206
    +--   deserializing the individual elements. This must only be used when the host
    
    207
    +--   platform uses little endian and the bitsize of the element type of the
    
    208
    +--   array is the one that is used for the serialized form of elements.
    
    209
    +getBCOByteArrayDirectly :: Storable a => Get (BCOByteArray a)
    
    210
    +getBCOByteArrayDirectly @a = do
    
    211
    +  size <- fromIntegral <$> getWord64le :: Get Int
    
    212
    +  SBS byteArray# <- toShort <$> getByteString (size * sizeOf (undefined :: a))
    
    213
    +    -- Beware that there is no overflow check for the byte count computation.
    
    214
    +  return (BCOByteArray byteArray#)
    
    215
    +
    
    216
    +#endif
    
    217
    +
    
    218 218
     -- See [BCOByteArray serialization].
    
    219 219
     instance Binary (BCOByteArray Word16) where
    
    220 220