[quandary] optimizing Quandary compare functions

Reviewed By: jeremydubreil

Differential Revision: D4179159

fbshipit-source-id: 2bae286
master
Sam Blackshear 8 years ago committed by Facebook Github Bot
parent 4a673f540d
commit b320714edd

@ -16,10 +16,13 @@ type t =
} }
let compare t1 t2 = let compare t1 t2 =
let n = Procname.compare t1.pname t2.pname in if t1 == t2
if n <> 0 then 0
then n else
else Location.compare t1.loc t2.loc let n = Procname.compare t1.pname t2.pname in
if n <> 0
then n
else Location.compare t1.loc t2.loc
let equal t1 t2 = let equal t1 t2 =
compare t1 t2 = 0 compare t1 t2 = 0

@ -138,9 +138,18 @@ module Make (Spec : Spec) = struct
type path = Passthroughs.t * (Source.t * Passthroughs.t) list * (Sink.t * Passthroughs.t) list type path = Passthroughs.t * (Source.t * Passthroughs.t) list * (Sink.t * Passthroughs.t) list
let compare t1 t2 = let compare t1 t2 =
Sources.compare t1.sources t2.sources if t1 == t2
|> next Sinks.compare t1.sinks t2.sinks then
|> next Passthroughs.compare t1.passthroughs t2.passthroughs 0
else
let n = Sources.compare t1.sources t2.sources in
if n <> 0
then n
else
let n = Sinks.compare t1.sinks t2.sinks in
if n <> 0
then n
else Passthroughs.compare t1.passthroughs t2.passthroughs
let equal t1 t2 = let equal t1 t2 =
compare t1 t2 = 0 compare t1 t2 = 0

@ -27,20 +27,25 @@ let base_compare ((var1, typ1) as base1) ((var2, typ2) as base2) =
if base1 == base2 if base1 == base2
then 0 then 0
else else
Var.compare var1 var2 let n = Var.compare var1 var2 in
|> next Typ.array_sensitive_compare typ1 typ2 if n <> 0
then n
else Typ.array_sensitive_compare typ1 typ2
let base_equal base1 base2 = let base_equal base1 base2 =
base_compare base1 base2 = 0 base_compare base1 base2 = 0
let access_compare access1 access2 = let access_compare access1 access2 =
if access1 == access2 if access1 == access2
then 0 then
0
else else
match access1, access2 with match access1, access2 with
| FieldAccess (f1, typ1), FieldAccess (f2, typ2) -> | FieldAccess (f1, typ1), FieldAccess (f2, typ2) ->
Ident.fieldname_compare f1 f2 let n = Ident.fieldname_compare f1 f2 in
|> next Typ.compare typ1 typ2 if n <> 0
then n
else Typ.compare typ1 typ2
| ArrayAccess typ1, ArrayAccess typ2 -> | ArrayAccess typ1, ArrayAccess typ2 ->
Typ.compare typ1 typ2 Typ.compare typ1 typ2
| FieldAccess _, _ -> 1 | FieldAccess _, _ -> 1
@ -53,16 +58,23 @@ let raw_compare ((base1, accesses1) as ap1) ((base2, accesses2) as ap2) =
if ap1 == ap2 if ap1 == ap2
then 0 then 0
else else
base_compare base1 base2 let n = base_compare base1 base2 in
|> next (IList.compare access_compare) accesses1 accesses2 if n <> 0
then n
else (IList.compare access_compare) accesses1 accesses2
let raw_equal ap1 ap2 = let raw_equal ap1 ap2 =
raw_compare ap1 ap2 = 0 raw_compare ap1 ap2 = 0
let compare ap1 ap2 = match ap1, ap2 with let compare ap1 ap2 =
| Exact ap1, Exact ap2 | Abstracted ap1, Abstracted ap2 -> raw_compare ap1 ap2 if ap1 == ap2
| Exact _, Abstracted _ -> 1 then
| Abstracted _, Exact _ -> (-1) 0
else
match ap1, ap2 with
| Exact ap1, Exact ap2 | Abstracted ap1, Abstracted ap2 -> raw_compare ap1 ap2
| Exact _, Abstracted _ -> 1
| Abstracted _, Exact _ -> (-1)
let equal ap1 ap2 = let equal ap1 ap2 =
compare ap1 ap2 = 0 compare ap1 ap2 = 0

@ -20,9 +20,14 @@ module CppSource = struct
| EnvironmentVariable (** source that was read from an environment variable *) | EnvironmentVariable (** source that was read from an environment variable *)
| Other (** for testing or uncategorized sources *) | Other (** for testing or uncategorized sources *)
let compare sk1 sk2 = match sk1, sk2 with let compare sk1 sk2 =
| Footprint ap1, Footprint ap2 -> AccessPath.compare ap1 ap2 if sk1 == sk2
| _ -> tags_compare sk1 sk2 then
0
else
match sk1, sk2 with
| Footprint ap1, Footprint ap2 -> AccessPath.compare ap1 ap2
| _ -> tags_compare sk1 sk2
let equal sk1 sk2 = let equal sk1 sk2 =
compare sk1 sk2 = 0 compare sk1 sk2 = 0
@ -83,8 +88,14 @@ module CppSource = struct
{ t with site = callee_site; } { t with site = callee_site; }
let compare src1 src2 = let compare src1 src2 =
Kind.compare src1.kind src2.kind if src1 == src2
|> next CallSite.compare src1.site src2.site then
0
else
let n = Kind.compare src1.kind src2.kind in
if n <> 0
then n
else CallSite.compare src1.site src2.site
let equal t1 t2 = let equal t1 t2 =
compare t1 t2 = 0 compare t1 t2 = 0
@ -163,8 +174,14 @@ module CppSink = struct
{ t with site = callee_site; } { t with site = callee_site; }
let compare snk1 snk2 = let compare snk1 snk2 =
Kind.compare snk1.kind snk2.kind if snk1 == snk2
|> next CallSite.compare snk1.site snk2.site then
0
else
let n = Kind.compare snk1.kind snk2.kind in
if n <> 0
then n
else CallSite.compare snk1.site snk2.site
let equal t1 t2 = let equal t1 t2 =
compare t1 t2 = 0 compare t1 t2 = 0

@ -89,8 +89,14 @@ module JavaSource = struct
{ t with site = callee_site; } { t with site = callee_site; }
let compare src1 src2 = let compare src1 src2 =
Kind.compare src1.kind src2.kind if src1 == src2
|> next CallSite.compare src1.site src2.site then
0
else
let n = Kind.compare src1.kind src2.kind in
if n <> 0
then n
else CallSite.compare src1.site src2.site
let pp fmt s = let pp fmt s =
F.fprintf fmt "%a(%a)" Kind.pp s.kind CallSite.pp s.site F.fprintf fmt "%a(%a)" Kind.pp s.kind CallSite.pp s.site
@ -185,8 +191,14 @@ module JavaSink = struct
{ t with site = callee_site; } { t with site = callee_site; }
let compare snk1 snk2 = let compare snk1 snk2 =
Kind.compare snk1.kind snk2.kind if snk1 == snk2
|> next CallSite.compare snk1.site snk2.site then
0
else
let n = Kind.compare snk1.kind snk2.kind in
if n <> 0
then n
else CallSite.compare snk1.site snk2.site
let pp fmt s = let pp fmt s =
F.fprintf fmt "%a(%a)" Kind.pp s.kind CallSite.pp s.site F.fprintf fmt "%a(%a)" Kind.pp s.kind CallSite.pp s.site

Loading…
Cancel
Save