Skip to content

Use private constants to define :toc_levels option#641

Merged
gettalong merged 1 commit intogettalong:masterfrom
ashmaroli:toc-levels-constant
Feb 22, 2020
Merged

Use private constants to define :toc_levels option#641
gettalong merged 1 commit intogettalong:masterfrom
ashmaroli:toc-levels-constant

Conversation

@ashmaroli
Copy link
Contributor

Motivation

This is to reduce array allocation when multiple Kramdown::Document objects are initialized with the same :toc_levels value.

Summary

When Kramdown::Document is initialized with option :toc_levels => [1, 2, 3, 4, 5, 6] use a predefined constant with identical contents instead of generating a new array from the option value or when Kramdown::Document is initialized with option :toc_levels => (1..6), use a predefined constant array instead of converting the range into a new Array.

It is safe to use constant values because the (merged) options attribute of Kramdown::Document instances is already frozen on initialization.

@gettalong gettalong self-assigned this Feb 22, 2020
@gettalong gettalong merged commit 0091596 into gettalong:master Feb 22, 2020
@gettalong
Copy link
Owner

Thank you!

@ashmaroli ashmaroli deleted the toc-levels-constant branch February 23, 2020 06:53
@seamusdemora seamusdemora mentioned this pull request Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants