Skip to content

Commit

Permalink
Fix for skipping mid
Browse files Browse the repository at this point in the history
  • Loading branch information
benbrandt committed Jan 13, 2024
1 parent 44ee63a commit 7e5de47
Show file tree
Hide file tree
Showing 13 changed files with 3,588 additions and 3,709 deletions.
9 changes: 5 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,9 +629,10 @@ where
let mut low = 0;
let mut high = sections.len().saturating_sub(1);
let mut last_chunk_size = None;
let mut mid = low + (high - low) / 2;

while low <= high {
let mid = low + (high - low) / 2;
mid = low + (high - low) / 2;
let (offset, str) = sections[mid];
let text_end = offset + str.len();
let chunk = self.text.get(start..text_end)?;
Expand Down Expand Up @@ -675,12 +676,12 @@ where
// Sometimes with tokenization, we can get a bigger chunk for
// the same amount of tokens.
if let Some(last_chunk_size) = last_chunk_size {
if last_chunk_size.fits.is_eq() {
for (offset, str) in sections.iter().skip(high) {
if last_chunk_size.fits.is_le() {
for (offset, str) in sections.iter().skip(mid) {
let text_end = offset + str.len();
let chunk = self.text.get(start..text_end)?;
let chunk_size = self.check_capacity(start, chunk);
if chunk_size.fits.is_eq() && chunk_size.size <= last_chunk_size.size {
if text_end >= end && chunk_size.size <= last_chunk_size.size {
end = text_end;
} else {
break;
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit 7e5de47

Please sign in to comment.