First, a reference before reading these patches is
http://bugs.darcs.net/issue2573
The review:
# more efficient definition of unlinesPS
Basically this:
-unlinesPS [] = BC.empty
-unlinesPS x = BC.init $ BC.unlines x
+unlinesPS [] = B.empty
+unlinesPS x = B.concat $ intersperse (BC.pack "\n") x
Looks correct, I guess this is more efficient becauses it does not
append then remove a last "\n".
Why not use (BC.singleton '\n') instead of (BC.pack "\n")?
# refactor, simplify, and document hunk application
This is a heavy one. The idea of breakAfter/BeforeNthNewline to
D.P.Prim.V1.Commute makes sense. That second function's type is
changed (along with the type of other functions of Commute).
applyHunkLines now returns an Either String FileContents instead of
a Maybe FileContents, to improve error reporting.
Also applyHunkLines applied a list of hunks to some FileContents, each
hunk being a triploe (offset,to_remove, to_insert). applyHunkLines was
therefore recursive
Now the new version of this function applies a single hunk. This makes
the code simpler to follow. The caller to applyHunkLines (in both old
and new
versions) is applyHunk(s).
But in fact applyHunkLines was always called with a list of one hunk as
argument (in hunkmod). So this simplification of the code is welcome.
Also this helps simplify the instance Apply Prim for the case of applying
a hunk.
As for correctness, I am just going to trust the quickcheck tests,
which pass.
OK then.
# re-format import list of Darcs.Util.ByteString
Just indenting and moving stuff around.
OK.
# fix betweenLinesPS and add a unit test
Reference:
https://hackage.haskell.org/package/bytestring-0.10.8.2/docs/Data-ByteString.html#v:breakSubstring
Reimplement betweenLinesPS in an efficient way. Also implement a simpler
and less efficient
spec_betweenLinesPS that is used to define a new QuickCheck property in
the test suite.
betweenLinesPS no longer uses linesPS and list-based functions, while
spec_betweenLinesPS
still does. A call to ByteString.Internals.toForeignPtr is removed.
Again, I'm going to trust QuickCheck on that one.
OK.
# throw out all access to bytestring internals from Darcs.Util.ByteString
Functions like isFunky, hashPS, fromPS2Hex, fromHex2PS are now defined
without C functions , so we can drop fpstring.c, yay!
We still have one use of unsafeWithInternals in Darcs.Util.Hash (to
calculate
SHA1 hashes). This will go away when we switch to cryptonite.
One question. linesPS definition is changed from:
~~~
linesPS ps
| B.null ps = [B.empty]
| otherwise = BC.split '\n' ps
~~~
To:
~~~
linesPS ps =
case search ps of
Nothing -> [ps]
Just n -> B.take n ps : linesPS (B.drop (n + 1) ps)
where
search = BC.elemIndex '\n'
~~~
Is the reason of this change to avoid the use of BC.split/B.split:
https://hackage.haskell.org/package/bytestring-0.10.8.2/docs/src/Data.ByteString.html#split
whose definition contains a call to accursedUnutterablePerformIO, a "bad"
function, judging from the mail thread mentioned in
http://bugs.darcs.net/issue2573 ?
Then how do we know that B.take, B.drop, BC.elemIndex will never be
implemented in terms
of this bad function?
|