Skip to content

Commit

Permalink
Avoid link agains base not ppxlib. This reduces the size from 23M to …
Browse files Browse the repository at this point in the history
…2.9M
  • Loading branch information
andersfugmann committed Jun 3, 2019
1 parent 13088a2 commit 1be9d66
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion drivers/generic/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name ppx_protocol_driver)
(public_name ppx_protocol_conv.driver)
(libraries ppx_protocol_conv ppx_protocol_conv.runtime)
(libraries ppx_protocol_conv.runtime)
(flags :standard -w -3)
(synopsis "generic (de)serialization driver for ppx_protocol_conv")
)
8 changes: 4 additions & 4 deletions drivers/generic/ppx_protocol_driver.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
open Protocol_conv
open Runtime
open Base
open StdLabels

module type Parameters = sig
val field_name: string -> string
Expand Down Expand Up @@ -62,7 +62,7 @@ module type Driver = sig
end

let mangle str =
match String.split_on_chars ~on:['_'] str with
match String.split_on_char ~sep:'_' str with
| s :: sx ->
String.concat ~sep:""
(s :: List.map ~f:String.capitalize sx)
Expand All @@ -87,7 +87,7 @@ module Make(Driver: Driver)(P: Parameters) = struct
let to_string_hum = Driver.to_string_hum

let raise_errorf t fmt =
Caml.Printf.kprintf (fun s -> raise (Protocol_error (s, t))) fmt
Printf.kprintf (fun s -> raise (Protocol_error (s, t))) fmt

let try_with: (t -> 'a) -> t -> ('a, error) Runtime.result = fun f t ->
match f t with
Expand Down Expand Up @@ -170,7 +170,7 @@ module Make(Driver: Driver)(P: Parameters) = struct
let mk_option t = Driver.of_alist [ ("__option", t) ] in
match of_value_fun v with
| t when Driver.is_null t -> mk_option t
| t when Option.is_some (get_option t) ->
| t when (get_option t) <> None ->
mk_option t
| t -> t

Expand Down
6 changes: 3 additions & 3 deletions drivers/json/dune
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
(library
(name protocol_conv_json)
(public_name ppx_protocol_conv_json)
(modules :standard \ test_expect)
(private_modules test_expect)
(libraries ppx_protocol_conv ppx_protocol_conv.runtime ppx_protocol_conv.driver yojson)
(libraries ppx_protocol_conv.runtime ppx_protocol_conv.driver yojson)
(synopsis "yojson (de)serialization driver for ppx_protocol_conv")
(inline_tests)
(preprocess (pps ppx_protocol_conv ppx_inline_test ppx_expect))
(preprocess (pps ppx_protocol_conv))
)
1 change: 0 additions & 1 deletion runtime/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
(library
(name protocol_conv)
(public_name ppx_protocol_conv.runtime)
(libraries base)
(synopsis "runtime library for ppx_protocol_conv")
)
11 changes: 6 additions & 5 deletions runtime/runtime.ml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ end
convert this exception into a [Driver.Protocol_exception]
*)
module Helper = struct
open Base
open StdLabels

(** Excpetion raised if the type could not be serialized *)
exception Protocol_error of string
Expand All @@ -118,8 +118,9 @@ module Helper = struct
end
module Hashtbl_lookup : Lookup = struct (* 20.22% *)
let of_alist alist =
let tbl = Hashtbl.of_alist_exn (module String) alist in
Hashtbl.find tbl
let tbl = Hashtbl.create 0 in
List.iter ~f:(fun (k, v) -> Hashtbl.add tbl k v) alist;
Hashtbl.find_opt tbl
end
module Lookup = Hashtbl_lookup

Expand Down Expand Up @@ -167,7 +168,7 @@ module Helper = struct
let f = inner 0 spec constr in

fun values ->
let value_array = Array.create ~len:count None in
let value_array = Array.make count None in
List.iter ~f:(fun (field, t) ->
match lookup field with
| None when strict -> raise_errorf "Unused field when deserialising record: %s" field
Expand Down Expand Up @@ -203,7 +204,7 @@ module Helper = struct
| Cons ((n1, f1, Some d1), xs) when omit_default ->
begin
let cont = inner xs in
fun acc v1 -> match Poly.equal d1 v1 with
fun acc v1 -> match d1 = v1 with
| true -> cont acc
| false -> cont ((n1, f1 v1) :: acc)
end
Expand Down

0 comments on commit 1be9d66

Please sign in to comment.