This commit is contained in:
Stew O'Connor 2023-06-01 19:36:21 -07:00
parent 054cdd87de
commit e052f362b2
4 changed files with 15 additions and 17 deletions

View File

@ -63,6 +63,7 @@ import Data.ByteArray qualified as BA
import Data.ByteArray.Encoding qualified as BE
import Data.ByteString qualified as B
import Data.ByteString.Lazy qualified as LB
import Data.ByteString.Lazy.Search qualified as SS
import Data.Char
import Data.Primitive.ByteArray
( ByteArray (ByteArray),
@ -81,8 +82,6 @@ import Unison.Prelude hiding (ByteString, empty)
import Unison.Util.Rope qualified as R
import Unsafe.Coerce (unsafeCoerce)
import Prelude hiding (drop, take)
import qualified Data.ByteString.Lazy.Search as SS
type Chunk = V.Vector Word8
@ -200,7 +199,7 @@ indexOf :: Bytes -> Bytes -> Maybe Word64
indexOf needle haystack =
case SS.indices needle' haystack' of
[] -> Nothing
(i:_) -> Just (fromIntegral i)
(i : _) -> Just (fromIntegral i)
where
needle' = toByteString needle
haystack' = toLazyByteString haystack

View File

@ -541,6 +541,7 @@ taket = binop0 1 $ \[x0, y, x] ->
dropt = binop0 1 $ \[x0, y, x] ->
unbox x0 Ty.natRef x $
TPrm DRPT [x, y]
atb = binop0 4 $ \[n0, b, n, t, r0, r] ->
unbox n0 Ty.natRef n
. TLetD t UN (TPrm IDXB [n, b])
@ -557,14 +558,14 @@ atb = binop0 4 $ \[n0, b, n, t, r0, r] ->
)
]
indext = binop0 3 $ \[x, y, t, r0, r] ->
indext = binop0 3 $ \[x, y, t, r0, r] ->
TLetD t UN (TPrm IXOT [x, y])
. TMatch t
. MatchSum
$ mapFromList
[ (0, ([], none )),
(1,
( [UN],
[ (0, ([], none)),
( 1,
( [UN],
TAbs r0
. TLetD r BX (TCon Ty.natRef 0 [r0])
$ some r
@ -572,13 +573,13 @@ indext = binop0 3 $ \[x, y, t, r0, r] ->
)
]
indexb = binop0 3 $ \[x, y, t, i, r] ->
indexb = binop0 3 $ \[x, y, t, i, r] ->
TLetD t UN (TPrm IXOB [x, y])
. TMatch t
. MatchSum
$ mapFromList
[ (0, ([], none)),
(1,
( 1,
( [UN],
TAbs i
. TLetD r BX (TCon Ty.natRef 0 [i])
@ -590,6 +591,7 @@ indexb = binop0 3 $ \[x, y, t, i, r] ->
sizet = unop0 1 $ \[x, r] ->
TLetD r UN (TPrm SIZT [x]) $
TCon Ty.natRef 0 [r]
unconst = unop0 7 $ \[x, t, c0, c, y, p, u, yp] ->
TLetD t UN (TPrm UCNS [x])
. TMatch t
@ -607,6 +609,7 @@ unconst = unop0 7 $ \[x, t, c0, c, y, p, u, yp] ->
)
)
]
unsnoct = unop0 7 $ \[x, t, c0, c, y, p, u, cp] ->
TLetD t UN (TPrm USNC [x])
. TMatch t

View File

@ -1503,7 +1503,6 @@ bprim2 !ustk !bstk EQLU i j = do
ustk <- bump ustk
poke ustk $ if universalEq (==) x y then 1 else 0
pure (ustk, bstk)
bprim2 !ustk !bstk IXOT i j = do
x <- peekOffBi bstk i
y <- peekOffBi bstk j
@ -1517,7 +1516,6 @@ bprim2 !ustk !bstk IXOT i j = do
poke ustk 1
pokeOffN ustk 1 i
pure (ustk, bstk)
bprim2 !ustk !bstk IXOB i j = do
x <- peekOffBi bstk i
y <- peekOffBi bstk j
@ -1531,7 +1529,6 @@ bprim2 !ustk !bstk IXOB i j = do
poke ustk 1
pokeOffN ustk 1 i
pure (ustk, bstk)
bprim2 !ustk !bstk DRPT i j = do
n <- peekOff ustk i
t <- peekOffBi bstk j

View File

@ -10,8 +10,8 @@ import Data.String (IsString (..))
import Data.Text qualified as T
import Data.Text.Encoding qualified as T
import Data.Text.Internal qualified as T
import Data.Text.Lazy qualified as TL
import Data.Text.Internal.Lazy.Search qualified as TL
import Data.Text.Lazy qualified as TL
import Data.Text.Unsafe qualified as T (Iter (..), iter)
import Data.Word (Word64)
import Unison.Util.Bytes qualified as B
@ -123,11 +123,10 @@ toText (Text t) = T.concat (chunkToText <$> unfoldr R.uncons t)
{-# INLINE toText #-}
indexOf :: Text -> Text -> Maybe Word64
indexOf needle haystack = unsafePerformIO $ do
pure $ case TL.indices needle' haystack' of
indexOf needle haystack =
case TL.indices needle' haystack' of
[] -> Nothing
(i:_) -> unsafePerformIO $ do
pure $ Just (fromIntegral i)
(i : _) -> Just (fromIntegral i)
where
needle' = toLazyText needle
haystack' = toLazyText haystack