Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Create array caches for variable map's keys and values

AuthorDaveJarvis <email>
Date2022-11-26 17:28:37 GMT-0800
Commit1eb19f210b20e404b1b9b3ad40aba3b9252071a3
Parente1e6386
Delta20 lines added, 15 lines removed, 5-line increase
src/main/java/com/keenwrite/sigils/RKeyOperator.java
private static final char KEY_SEPARATOR_R = '$';
+ private final StringBuilder mVarName = new StringBuilder( 128 );
+
/**
* Constructs a new instance capable of converting dot-separated variable
* names into R's dollar-symbol-separated names.
*/
- public RKeyOperator() {}
+ public RKeyOperator() { }
/**
assert !key.isBlank();
- final var rVarName = new StringBuilder( key.length() + 3 );
- rVarName.append( "v" );
- rVarName.append( KEY_SEPARATOR_R );
- rVarName.append( key );
+ mVarName.setLength( 0 );
+
+ //final var rVarName = new StringBuilder( key.length() + 3 );
+ mVarName.append( "v" );
+ mVarName.append( KEY_SEPARATOR_R );
+ mVarName.append( key );
// The 3 is for v$ + first char, which cannot be a separator.
- for( int i = rVarName.length() - 1; i >= 3; i-- ) {
- if( rVarName.charAt( i ) == KEY_SEPARATOR_DEF ) {
- rVarName.setCharAt( i, KEY_SEPARATOR_R );
+ for( int i = mVarName.length() - 1; i >= 3; i-- ) {
+ if( mVarName.charAt( i ) == KEY_SEPARATOR_DEF ) {
+ mVarName.setCharAt( i, KEY_SEPARATOR_R );
}
}
- return rVarName.toString();
+ return mVarName.toString();
}
}
src/main/java/com/keenwrite/processors/text/AhoCorasickReplacer.java
* Default (empty) constructor.
*/
- protected AhoCorasickReplacer() {
- }
+ protected AhoCorasickReplacer() { }
@Override
public String replace( final String text, final Map<String, String> map ) {
// Create a buffer sufficiently large that re-allocations are minimized.
- final var sb = new StringBuilder( (int)(text.length() * 1.25) );
+ final var sb = new StringBuilder( (int) (text.length() * 1.25) );
// Definition names cannot overlap.
src/main/java/com/keenwrite/processors/text/StringUtilsReplacer.java
package com.keenwrite.processors.text;
+import org.apache.commons.lang3.StringUtils;
+
import java.util.Map;
import static org.apache.commons.lang3.StringUtils.replaceEach;
/**
- * Replaces text using Apache's StringUtils.replaceEach method.
+ * Replaces text using a brute-force
+ * {@link StringUtils#replaceEach(String, String[], String[])}} method.
*/
public class StringUtilsReplacer extends AbstractTextReplacer {
/**
* Default (empty) constructor.
*/
- protected StringUtilsReplacer() {
- }
+ protected StringUtilsReplacer() { }
@Override