Sink

private class Sink(val sb: StringBuilder)

One line call's state: the buffer and the ancestors on the way down — one lifetime, so they travel as fields rather than through every signature.

Constructors

Link copied to clipboard
constructor(sb: StringBuilder)

Properties

Link copied to clipboard
private val chain: MutableSet<Any>

The containers between the root and the current element, by IDENTITY: equals/hashCode are caller code that recurses over the structure being walked, so equality would blow the stack this protects.

Link copied to clipboard
private val sb: StringBuilder

Functions

Link copied to clipboard
private inline fun descend(v: Any, body: () -> Boolean): Boolean

v is on the chain for the duration of body, and the buffer is rolled back when body repaired nothing. Removed on the way out: the same list twice as SIBLINGS is not a cycle. Depth is measured here rather than per element, since only a container can be descended into — a scalar sitting at the limit is a leaf, and reads as itself.

Link copied to clipboard
private fun element(e: Any?): Boolean
Link copied to clipboard
private fun flatArray(v: Any): Boolean

Tried BEFORE the container branches: a boxed unsigned array implements java.util.Collection, so walked as one it would repair nothing and fall back to the signed storage its toString() prints.

Link copied to clipboard
fun render(v: Any)

Append v's rendering, falling back to its own toString() and containing whatever it throws.

Link copied to clipboard
fun shape(v: Any): Boolean

Append v's repair; false when toString() is already the best answer.

Link copied to clipboard
private fun walk(owner: Any, items: Iterable<*>, open: Char, close: Char, always: Boolean): Boolean

owner is what joins the chain; items is what gets rendered — the same object for a collection, an array view for an array, its components for a tuple.

Link copied to clipboard
private fun walkMap(map: Map<*, *>): Boolean

AbstractMap's own {k=v, k2=v2}, so a walked map reads the same as an unwalked one.