rajat315315 opened a new issue, #16421:
URL: https://github.com/apache/lucene/issues/16421

   ### Description
   
   ## Issue Description
   
   In `org.apache.lucene.analysis.hunspell.Dictionary#readAffixFile`, affix 
directives (such as `PFX`, `SFX`, `CIRCUMFIX`, `KEEPCASE`, `NEEDAFFIX`, etc.) 
were being checked sequentially using a large `if-else` chain spanning over 120 
lines. 
   
   The code previously included a TODO comment asking:
   ```java
   // TODO: convert to a switch?
   ```
   
   Using a modern Java `switch` statement on `firstWord` simplifies this 
construct, improves code readability, and allows the Java compiler to produce a 
more efficient bytecode lookup scheme rather than sequential `String.equals()` 
comparisons.
   
   ## Proposed Changes
   
   1. **Refactor `readAffixFile` Directive Parser**:
      - Replace the `if ("AF".equals(firstWord)) ... else if ...` chain in 
`Dictionary.java` with a `switch (firstWord)` statement.
      - Combine multi-label cases sharing identical logic (e.g. `"NEEDAFFIX", 
"PSEUDOROOT"` and `"ICONV", "OCONV"`).
      - Removed the stale `// TODO: convert to a switch?` comment.
   
   2. **Refactor Related Directive Helpers**:
      - `getDecoderAndFlagParsingStrategy`: Converted `"SET"` / `"FLAG"` header 
check loop from `if-else` to `switch (firstWord)`.
      - `getFlagParsingStrategy`: Refactored `if ("num".equals(flagType))` 
chain to a concise `switch` expression returning strategy instances.
   
   ## Benefits
   
   - **Readability & Maintainability**: Clearer structure and alignment across 
all Hunspell directive handlers.
   - **Performance**: Better bytecode optimization with 
`tableswitch`/`lookupswitch` over linear string comparisons.
   - **Code Cleanliness**: Resolves existing `TODO` comment.
   
   ## Verification
   
   Ran all Hunspell analysis tests:
   ```bash
   ./gradlew :lucene:analysis:common:test --tests 
"org.apache.lucene.analysis.hunspell.*"
   ```
   **Result**: Build succeeded, all 158 tests passed.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to