Skip to content

Dead code: LongestCommonSubsequence.EnsureHashCodes2 range-expansion never executes #24

Description

@lassevk

LongestCommonSubsequence<T>.EnsureHashCodes2 (src/DiffLib/LongestCommonSubsequence.cs:85-110) has two while loops that lazily extend the hashcode index of collection2 downward/upward:

while (_HashCodes2Lower > lower) { ... }
while (_HashCodes2Upper < upper) { ... }

These are never reached. The very first call comes from LongestCommonSubsectionDiff.Calculate, which always passes the full range [0, collection2.Count). Every recursive Find call afterwards uses sub-ranges, so _HashCodes2Lower is already 0 (never > lower) and _HashCodes2Upper is already Count (never < upper). Coverage confirms lines 99–109 are never executed.

So the "lazy/incremental" design was either intended to be driven differently (build the index only for the sub-range actually needed) or is leftover from an earlier version. Two possible resolutions:

  1. Remove the dead code and the _FirstHashCodes2 / _HashCodes2Lower / _HashCodes2Upper bookkeeping, since the index is always built once for the full range — simplifies the class considerably.
  2. Actually make it lazy (build the index for the requested sub-range on demand) if the original intent was to avoid indexing the whole of collection2 up front for large inputs.

Worth deciding which, because right now it's carrying complexity that does nothing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions