nixfmt icon indicating copy to clipboard operation
nixfmt copied to clipboard

Predoc: Fix quadratic complexities in nest and offset

Open dasJ opened this issue 7 months ago • 4 comments

I honestly don't understand why this makes it faster, but for me the test suite runs ~2s faster now. This is an AI-generated contribution. The GPT explanation is:

By abstracting the transformation logic into a single function transform, we can pass different transformations for nesting and offsetting. This way, we avoid repeated traversals and ensure each element is processed exactly once.

This change ensures linear complexity for the nest and offset functions. We leverage the map function to traverse and transform the Doc structure only once, applying the necessary changes to each element.

dasJ avatar Jul 01 '24 12:07 dasJ