Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check for invalid index values before looping
Checking for NA, NaN, and +/-Inf values in the first position of the if-else statement was a bad idea for performance reasons, but was also incorrect. Any time two merged objects had different start or end index values, xp or yp ar outside the bounds of their respective index vectors. That didn't cause a segfault though, because R_FINITE() would happily interpret the random memory as either a number or NaN. This would manifest as an error when there should be none, or an infinite loop. We can fix the logic and improve performance by taking advantage of the fact that the indexes are sorted. Therefore, if present, -Inf will always be in the first element, while NA, Inf, and NaN will always be in the last element. In the case of an integer index, the NA will always be last (because that's how it sorts in R, even though it's equal to INT_MIN in C). See #174.
- Loading branch information