Skip to content

Commit b1a05c3

Browse files
nomeatatreeowl
authored andcommitted
Avoid two-layers of pattern matchin in union (#537)
by matching on the size field instead. I expect this to yield (slightly) more efficient code. According to the benchmark, this yields a 4% speed improvement for `union` and 3% for `unions`.
1 parent 1e91479 commit b1a05c3

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

Data/Set/Internal.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,8 @@ unions = foldlStrict union empty
715715
-- equal elements are encountered.
716716
union :: Ord a => Set a -> Set a -> Set a
717717
union t1 Tip = t1
718-
union t1 (Bin _ x Tip Tip) = insertR x t1
719-
union (Bin _ x Tip Tip) t2 = insert x t2
718+
union t1 (Bin 1 x _ _) = insertR x t1
719+
union (Bin 1 x _ _) t2 = insert x t2
720720
union Tip t2 = t2
721721
union t1@(Bin _ x l1 r1) t2 = case splitS x t2 of
722722
(l2 :*: r2)

0 commit comments

Comments
 (0)