Skip to content

Commit

Permalink
Fixed indexing bug in ByteString traversals
Browse files Browse the repository at this point in the history
  • Loading branch information
shachaf committed Jan 21, 2013
1 parent e546387 commit e5a3860
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Control/Lens/Internal/ByteString.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ traversedStrictTree :: Int -> IndexedTraversal' Int B.ByteString Word8
traversedStrictTree i0 pafb (BI.PS fp off len) = rebuild len <$> go i0 (i0 + len)
where
p = unsafeForeignPtrToPtr fp `plusPtr` (off - i0)
rebuild n f = unsafeCreate n $ \q -> f q
rebuild n f = unsafeCreate n $ \q -> f (q `plusPtr` (off - i0))
go !i !j
| i + grain < j, k <- i + div (j - i) 2 = (\l r q -> l q >> r q) <$> go i k <*> go k j
| otherwise = run i j
Expand All @@ -108,7 +108,7 @@ traversedStrictTree8 :: Int -> IndexedTraversal' Int B.ByteString Char
traversedStrictTree8 i0 pafb (BI.PS fp off len) = rebuild len <$> go i0 (i0 + len)
where
p = unsafeForeignPtrToPtr fp `plusPtr` (off - i0)
rebuild n f = unsafeCreate n $ \q -> f q
rebuild n f = unsafeCreate n $ \q -> f (q `plusPtr` (off - i0))
go !i !j
| i + grain < j, k <- i + div (j - i) 2 = (\l r q -> l q >> r q) <$> go i k <*> go k j
| otherwise = run i j
Expand Down

0 comments on commit e5a3860

Please sign in to comment.