Skip to content

Commit

Permalink
fix len panic after clear (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiling-J authored Sep 2, 2023
1 parent a3e36fe commit 21382fb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,17 @@ impl MetaData {
let tmp = &mut self.data[index as usize];
entry.index = index;
_ = replace(tmp, entry);
self.keys.insert(CompactString::new(key), index);
if !key.starts_with("__root:") {
self.keys.insert(CompactString::new(key), index);
}
&mut self.data[index as usize]
} else {
let index = self.data.len();
entry.index = index as u32;
self.data.push(entry);
self.keys.insert(CompactString::new(key), index as u32);
if !key.starts_with("__root:") {
self.keys.insert(CompactString::new(key), index as u32);
}
&mut self.data[index]
}
}
Expand All @@ -387,7 +391,7 @@ impl MetaData {
}

pub fn len(&self) -> usize {
self.keys.len() - self.meta_key_count
self.keys.len()
}
}

Expand Down Expand Up @@ -542,5 +546,7 @@ mod tests {
assert_eq!(metadata.len(), 1);
metadata.remove(index_b);
assert_eq!(metadata.len(), 0);
metadata.clear();
assert_eq!(metadata.len(), 0);
}
}

0 comments on commit 21382fb

Please sign in to comment.