From 1be9d66f8f1ef60089d8c8f10b7135cc83fea40b Mon Sep 17 00:00:00 2001 From: Anders Fugmann Date: Mon, 3 Jun 2019 14:54:29 +0200 Subject: [PATCH] Avoid link agains base not ppxlib. This reduces the size from 23M to 2.9M --- drivers/generic/dune | 2 +- drivers/generic/ppx_protocol_driver.ml | 8 ++++---- drivers/json/dune | 6 +++--- runtime/dune | 1 - runtime/runtime.ml | 11 ++++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/generic/dune b/drivers/generic/dune index 4f12f4d..859a437 100644 --- a/drivers/generic/dune +++ b/drivers/generic/dune @@ -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") ) diff --git a/drivers/generic/ppx_protocol_driver.ml b/drivers/generic/ppx_protocol_driver.ml index b3aa338..6d1e00f 100644 --- a/drivers/generic/ppx_protocol_driver.ml +++ b/drivers/generic/ppx_protocol_driver.ml @@ -1,6 +1,6 @@ open Protocol_conv open Runtime -open Base +open StdLabels module type Parameters = sig val field_name: string -> string @@ -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) @@ -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 @@ -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 diff --git a/drivers/json/dune b/drivers/json/dune index 10d8711..9b2bae5 100644 --- a/drivers/json/dune +++ b/drivers/json/dune @@ -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)) ) diff --git a/runtime/dune b/runtime/dune index ee81208..8fc4c8c 100644 --- a/runtime/dune +++ b/runtime/dune @@ -1,6 +1,5 @@ (library (name protocol_conv) (public_name ppx_protocol_conv.runtime) - (libraries base) (synopsis "runtime library for ppx_protocol_conv") ) diff --git a/runtime/runtime.ml b/runtime/runtime.ml index afa98d6..90376dd 100644 --- a/runtime/runtime.ml +++ b/runtime/runtime.ml @@ -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 @@ -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 @@ -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 @@ -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