llvm::yaml::Output::paddedKey unconditionally outputs spaces, which
are superfluous if the value to be dumped is a sequence or map.
Change bool NeedsNewLine to StringRef Padding so that it can be
overridden to \n if the value is a sequence or map.
An empty map/sequence is special. It is printed as {} or [] without
a newline, while a non-empty map/sequence follows a newline. To handle
this distinction, add another variable PaddingBeforeContainer and does
the special handling in endMapping/endSequence.
Looks like you could move this to before the if?