Problem
The three sync modifiers (synccomputesmodifier.ts, syncfixesmodifier.ts, syncvariablesmodifier.ts) have ~80% code duplication, specifically in the Data1D processing logic (lines ~55-118 in each file).
Current Behavior
Each modifier contains nearly identical code for:
- Getting
data1DNames and checking size
- Processing
clearPerSync logic
- Looping through
data1DVector and extracting x/y values
- Proper cleanup of WASM objects (
data1DNamesWrapper, lmpData, data1DVector)
Expected Behavior
Extract the common Data1D processing logic into a shared helper function that can be reused by all three modifiers.
Proposed Solution
Create a shared helper function in src/modifiers/modifier.ts (or a new utility file):
function processData1D(
modifier: LMPModifier,
data1D: Data1D | undefined,
input: ModifierInput,
everything: boolean,
syncDataPoints: boolean
): Data1D | undefined
This function should handle:
- Getting
data1DNames wrapper and extracting size
- Checking if data1D needs to be created
- Processing
clearPerSync logic
- Looping through
data1DVector and extracting x/y values from WASM memory
- Proper cleanup of all WASM objects
- Returning the processed
data1D object
Files to Modify
src/modifiers/modifier.ts (add helper function)
- OR create new utility file if preferred
Benefits
- Reduces code duplication (~125 lines per file → ~50-60 lines)
- Makes maintenance easier (fix bugs/improvements in one place)
- Ensures consistent WASM memory cleanup
- Easier to add new modifiers in the future
Related
This is a prerequisite for issue #183 (memory leak fixes) and will make future improvements easier. Should be done after basic memory leak fixes.
Problem
The three sync modifiers (
synccomputesmodifier.ts,syncfixesmodifier.ts,syncvariablesmodifier.ts) have ~80% code duplication, specifically in the Data1D processing logic (lines ~55-118 in each file).Current Behavior
Each modifier contains nearly identical code for:
data1DNamesand checking sizeclearPerSynclogicdata1DVectorand extracting x/y valuesdata1DNamesWrapper,lmpData,data1DVector)Expected Behavior
Extract the common Data1D processing logic into a shared helper function that can be reused by all three modifiers.
Proposed Solution
Create a shared helper function in
src/modifiers/modifier.ts(or a new utility file):This function should handle:
data1DNameswrapper and extracting sizeclearPerSynclogicdata1DVectorand extracting x/y values from WASM memorydata1DobjectFiles to Modify
src/modifiers/modifier.ts(add helper function)Benefits
Related
This is a prerequisite for issue #183 (memory leak fixes) and will make future improvements easier. Should be done after basic memory leak fixes.