Commits

camlspotter committed 4a2a99b

safe unsafes

  • Participants
  • Parent commits bbef01e

Comments (0)

Files changed (3)

File ocaml/lex.ml

       if src >= l then
         if dst >= l then s else String.sub s 0 dst
       else
-        match s.[src] with
+        match String.unsafe_get s src with
           '_' -> remove (src + 1) dst
-        |  c  -> s.[dst] <- c; remove (src + 1) (dst + 1)
+        |  c  -> String.unsafe_set s dst c; remove (src + 1) (dst + 1)
     in remove 0 0
 
   let char_for_backslash = function
 let char_internal = 
   (perform
      s <-- matched newline;
-     return s.[0] (* Funny that only the first char is used *))
+     return (String.unsafe_get s 0) (* Funny that only the first char is used *))
   <|> tokenp (function '\\' | '\'' | '\010' | '\013' -> false
                      | _ -> true)
   <|> (* '\\' case *)
        <!> (matched (token '*' >>= fun _ -> ignore (takeWhile  is_symbolchar)) >>= function
               | "*" -> return_with_pos STAR
               | s ->
-                  if s.[1] = '*' then return_with_pos (INFIXOP4 s) (* ** case *)
+                  if String.unsafe_get s 1 = '*' then return_with_pos (INFIXOP4 s) (* ** case *)
                   else return_with_pos (INFIXOP3 s)))
 
   <|> (* case of '#' *)

File ocaml/plparser.ml

   mkexp(Pexp_apply(mkoperator name 2, ["", arg1; "", arg2]))
 
 let neg_float_string f =
-  if String.length f > 0 && f.[0] = '-'
+  if String.length f > 0 && String.unsafe_get f 0 = '-'
   then String.sub f 1 (String.length f - 1)
   else "-" ^ f
 

File ocaml/plphelper.ml

           NEW NATIVEINT PREFIXOP STRING TRUE UIDENT
 *)
     | _ -> 
-        match op.[0] with
+        match String.unsafe_get op 0 with
         | '!' | '~' | '?' -> { prec = 100.0; kind = `Prefix }
         | '=' | '<' | '>' | '|' | '&' | '$' -> infixop0
         | '@' | '^' -> infixop1