Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use private constants to define :toc_levels option #641

Merged
merged 1 commit into from
Feb 22, 2020

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