| | package com.keenwrite.sigils; |
| | |
| | +import com.keenwrite.collections.BoundedCache; |
| | + |
| | import java.util.function.UnaryOperator; |
| | |
 |
| | private static final char KEY_SEPARATOR_R = '$'; |
| | |
| | + /** Minor optimization to avoid recreating an object. */ |
| | private final StringBuilder mVarName = new StringBuilder( 128 ); |
| | + |
| | + /** Optimization to avoid re-converting variable names into R format. */ |
| | + private final BoundedCache<String, String> mVariables = new BoundedCache<>( |
| | + 2048 |
| | + ); |
| | |
| | /** |
 |
| | assert !key.isBlank(); |
| | |
| | - mVarName.setLength( 0 ); |
| | + return mVariables.computeIfAbsent( key, this::convert ); |
| | + } |
| | |
| | - //final var rVarName = new StringBuilder( key.length() + 3 ); |
| | + private String convert( final String key ) { |
| | + mVarName.setLength( 0 ); |
| | mVarName.append( "v" ); |
| | mVarName.append( KEY_SEPARATOR_R ); |