Skip to content

Conversation

gullit-cw
Copy link

Summary

This PR implements a dedicated line mode diffing functionality for the go-diff library, providing users with a more efficient and predictable way to perform line-based text comparisons.

Changes

New Features

  • DiffLineMode method: A new public method that always uses line mode regardless of text length, providing consistent behavior for line-based diffing scenarios
  • DiffFunction type: A new function type that encapsulates diff computation logic, enabling more flexible and testable diff implementations
  • DiffCleanupLineBased method: Specialized cleanup function for line-based diffs that merges consecutive operations and removes trivial equalities

Refactoring

  • Improved DiffMainRunes: Refactored to use closure-based approach for better encapsulation of deadline and line mode logic
  • Enhanced diffCompute: Updated to use the new DiffFunction type for more flexible diff computation
  • Better separation of concerns: Cleaner separation between line mode and character-based diffing logic

Infrastructure

  • Go version update: Updated from Go 1.13 to Go 1.24 for better compatibility and performance
  • Dependency cleanup: Streamlined go.mod and go.sum files

Benefits

  1. Performance: Line mode diffing is significantly faster for large text files with line-based changes
  2. Predictability: DiffLineMode provides consistent behavior regardless of input size
  3. Maintainability: Better code structure and separation of concerns
  4. Testability: Comprehensive test coverage for all new functionality
  5. Backward compatibility: All existing functionality remains unchanged

Testing

  • ✅ All existing tests pass
  • ✅ New comprehensive test suite for DiffLineMode functionality
  • ✅ Tests cover edge cases including empty strings, Unicode, and invalid UTF-8 sequences
  • ✅ Performance benchmarks included for the new cleanup function

Usage Example

dmp := New()

// Always use line mode, regardless of text length
diffs := dmp.DiffLineMode(text1, text2)

// The new method provides consistent line-based diffing behavior
// without the complexity of the existing checklines parameter

Breaking Changes

None. This is a purely additive change that maintains full backward compatibility.

Related Issues

This implementation addresses the need for more efficient and predictable line-based diffing in scenarios where character-level precision is not required.

- Add DiffLineMode method for always-on line mode diffing
- Introduce DiffFunction type for flexible diff computation
- Add DiffCleanupLineBased for line-specific diff optimization
- Refactor diffMainRunes to use closure-based approach
- Update Go version to 1.24 and clean up dependencies
- Add comprehensive test coverage for new functionality
@gullitmiranda gullitmiranda force-pushed the feat/implement-diff-line-mode branch from 83e187c to 0569de3 Compare August 21, 2025 15:03
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