-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BatString.ml should use unsafe versions of set and get #836
Conversation
ff28298
to
6f1f376
Compare
Is it always guaranteed that i is in [0..n-1]? |
I have carefully reviewed the changes again, and believe so, yes. |
In 266d5f6 I started annotating occurrences of (In OCaml, |
I'll try to read the full diff tomorrow. |
266d5f6
to
fbe2d2a
Compare
A great idea! I've added assertions to those functions that are affected by the PR (except a couple of really trivial cases), so that we could be more sure that the change does not cause regressions. |
src/batString.mlv
Outdated
if BatChar.is_digit (unsafe_get s1 0) && BatChar.is_digit (unsafe_get s2 0) then | ||
(* groups are never empty, so index 0 is always valid *) | ||
if BatChar.is_digit (unsafe_get s1 0) && | ||
BatChar.is_digit (unsafe_get s2 0) then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't trust the Enum
module enough to ensure this property (or have you went to annotate all Enum
functions involved here with static assertions to "prove" this as well?). You don't risk undefined behavior on trusting another module's interface specifications. I that you must use safe accessors here -- in any case, the overhead of Enum largely drowns out any bound access cost.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your arguments are convincing. I've reverted this change.
fbe2d2a
to
1cac929
Compare
'len-1' should be written 'len - 1'. |
Appart for lines 405..410 and 732 (indentation), I am OK with the changes. |
I've reverted a few unnecessary changes. |
The branch was rebased to resolve conflicts. Are there any outstanding issues remaining? |
Thanks for the ping, merged. (For the record, I have mixed feelings about using unsafe operations, but I believe we have used due diligence here to avoid problems.) |
This gives a slight performance boost to one of my programs.