diff options
| author | Maxime Dénès | 2017-10-06 12:37:15 +0200 |
|---|---|---|
| committer | Maxime Dénès | 2017-10-06 12:37:15 +0200 |
| commit | 3134ddd5dae8c9ab78a8aad181b2142f63907ecb (patch) | |
| tree | d31ff1ae34bc0a8fd0608ad19d545c916d0d85db /lib | |
| parent | fb45ec112ebdf6f18143b844e317a555f14e3b74 (diff) | |
| parent | 8fa1d224dafde29f5b527d380c069f196a042c60 (diff) | |
Merge PR #1125: [pp] Minor optimization in `Pp.t` construction and gluing.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/pp.ml | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -82,10 +82,21 @@ let utf8_length s = done ; !cnt -let app s1 s2 = match s1, s2 with - | Ppcmd_empty, s - | s, Ppcmd_empty -> s - | s1, s2 -> Ppcmd_glue [s1; s2] +let rec app d1 d2 = match d1, d2 with + | Ppcmd_empty, d + | d, Ppcmd_empty -> d + + (* Optimizations *) + | Ppcmd_glue [l1;l2], Ppcmd_glue l3 -> Ppcmd_glue (l1 :: l2 :: l3) + | Ppcmd_glue [l1;l2], d2 -> Ppcmd_glue [l1 ; l2 ; d2] + | d1, Ppcmd_glue l2 -> Ppcmd_glue (d1 :: l2) + + | Ppcmd_tag(t1,d1), Ppcmd_tag(t2,d2) + when t1 = t2 -> Ppcmd_tag(t1,app d1 d2) + | d1, d2 -> Ppcmd_glue [d1; d2] + (* Optimizations deemed too costly *) + (* | Ppcmd_glue l1, Ppcmd_glue l2 -> Ppcmd_glue (l1 @ l2) *) + (* | Ppcmd_string s1, Ppcmd_string s2 -> Ppcmd_string (s1 ^ s2) *) let seq s = Ppcmd_glue s |
