[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,6 +16,9 @@ type t =
}
let compare t1 t2 =
if t1 == t2
then 0
else
let n = Procname.compare t1.pname t2.pname in
if n <> 0
then n

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

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

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

@ -89,8 +89,14 @@ module JavaSource = struct
{ t with site = callee_site; }
let compare src1 src2 =
Kind.compare src1.kind src2.kind
|> next CallSite.compare src1.site src2.site
if src1 == src2
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 =
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; }
let compare snk1 snk2 =
Kind.compare snk1.kind snk2.kind
|> next CallSite.compare snk1.site snk2.site
if snk1 == snk2
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 =
F.fprintf fmt "%a(%a)" Kind.pp s.kind CallSite.pp s.site

Loading…
Cancel
Save