+/* Fast heuristic cost evaluation to use in the inner loop of the match-finder.
+ * Unlike lzms_match_cost() which does a true cost evaluation, this simply
+ * prioritize matches based on their offset. */
+static input_idx_t
+lzms_match_cost_fast(input_idx_t length, input_idx_t offset, const void *_lru)
+{
+ const struct lzms_lz_lru_queues *lru = _lru;
+
+
+ /* It seems well worth it to take the time to give priority to recently
+ * used offsets. */
+ for (input_idx_t i = 0; i < LZMS_NUM_RECENT_OFFSETS; i++)
+ if (offset == lru->recent_offsets[i])
+ return i;
+
+ return offset;
+}
+
+static void
+lzms_lz_skip_bytes(struct lzms_compressor *ctx, u32 n)
+{
+ while (n--)
+ lz_sarray_skip_position(&ctx->lz_sarray);
+}
+
+static struct raw_match
+lzms_get_near_optimal_match(struct lzms_compressor *ctx)
+{
+ struct raw_match matches[10];
+ u32 num_matches;
+
+ num_matches = lz_sarray_get_matches(&ctx->lz_sarray,
+ matches,
+ lzms_match_cost_fast,
+ &ctx->lru.lz);
+ if (num_matches == 0)
+ return (struct raw_match) { .len = 0 };
+