port print utils + refactoring
commitc845293e5239131e3cca4ab619e0d8854883c849
authorSteve Cao <shiqicao@fb.com>
Mon, 30 Mar 2020 22:14:30 +0000 (30 15:14 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Mon, 30 Mar 2020 22:17:40 +0000 (30 15:17 -0700)
treed5b24b0bc5247b8e6b5eca429d2ef8339ac80faf
parent88eb261b574eae39f86688deceb2a20cb2227bda
port print utils + refactoring

Summary:
- Aast shapes are printed as darray, in Ocaml new darrays are created from shape key and values. However, creating aast nodes implies extra allocation cost and hurts perf. Darray printing logic are factored out into more abstract implementation, which can be applied to both darray and shape without creating aast node.

- Introduced `then_write(cond: bool, str: AsRef<str>) -> Result<(), Error>` to make printing logic more concise and improve readability. Not all `if ... { w.write(...) }` changed to `then_write`, I prefer doing this kind refactoring in a separate diff, which is easy to show no regression.

- ported `SSwitch` printing with new slice pattern, I like it very much!

Differential Revision: D20690069

fbshipit-source-id: 0c5e82204c13916f9f0d8d15b1fb47ea0cd15caa
hphp/hack/src/hhbc/print.rs
hphp/hack/src/hhbc/write.rs