Add remove_from_all method to Corpus trait (#2259)

* add remove_from_all

* a

* a

* aaaaaaa

* make remove_from_all to remove
This commit is contained in:
Dongjia "toka" Zhang 2024-05-30 11:53:32 +02:00 committed by GitHub
parent b96b9be674
commit e912216a37
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 13 additions and 12 deletions

View File

@ -107,9 +107,8 @@ where
self.inner.replace(idx, testcase) self.inner.replace(idx, testcase)
} }
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases.
#[inline] fn remove(&mut self, idx: CorpusId) -> Result<Testcase<Self::Input>, Error> {
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
let testcase = self.inner.remove(idx)?; let testcase = self.inner.remove(idx)?;
self.cached_indexes.borrow_mut().retain(|e| *e != idx); self.cached_indexes.borrow_mut().retain(|e| *e != idx);
Ok(testcase) Ok(testcase)

View File

@ -396,12 +396,14 @@ where
.ok_or_else(|| Error::key_not_found(format!("Index {idx} not found"))) .ok_or_else(|| Error::key_not_found(format!("Index {idx} not found")))
} }
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
#[inline] #[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> { fn remove(&mut self, idx: CorpusId) -> Result<Testcase<Self::Input>, Error> {
self.storage let mut testcase = self.storage.enabled.remove(idx);
.enabled if testcase.is_none() {
.remove(idx) testcase = self.storage.disabled.remove(idx);
}
testcase
.map(|x| x.take()) .map(|x| x.take())
.ok_or_else(|| Error::key_not_found(format!("Index {idx} not found"))) .ok_or_else(|| Error::key_not_found(format!("Index {idx} not found")))
} }

View File

@ -112,7 +112,7 @@ where
Ok(entry) Ok(entry)
} }
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled corpus
#[inline] #[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> { fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
let entry = self.inner.remove(idx)?; let entry = self.inner.remove(idx)?;

View File

@ -113,7 +113,7 @@ pub trait Corpus: UsesInput + Serialize + for<'de> Deserialize<'de> {
testcase: Testcase<Self::Input>, testcase: Testcase<Self::Input>,
) -> Result<Testcase<Self::Input>, Error>; ) -> Result<Testcase<Self::Input>, Error>;
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
fn remove(&mut self, id: CorpusId) -> Result<Testcase<Self::Input>, Error>; fn remove(&mut self, id: CorpusId) -> Result<Testcase<Self::Input>, Error>;
/// Get by id; considers only enabled testcases /// Get by id; considers only enabled testcases

View File

@ -63,7 +63,7 @@ where
Err(Error::unsupported("Unsupported by NopCorpus")) Err(Error::unsupported("Unsupported by NopCorpus"))
} }
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
#[inline] #[inline]
fn remove(&mut self, _idx: CorpusId) -> Result<Testcase<I>, Error> { fn remove(&mut self, _idx: CorpusId) -> Result<Testcase<I>, Error> {
Err(Error::unsupported("Unsupported by NopCorpus")) Err(Error::unsupported("Unsupported by NopCorpus"))

View File

@ -112,7 +112,7 @@ where
self.inner.peek_free_id() self.inner.peek_free_id()
} }
/// Removes an entry from the corpus, returning it if it was present. /// Removes an entry from the corpus, returning it if it was present; considers both enabled and disabled testcases
#[inline] #[inline]
fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> { fn remove(&mut self, idx: CorpusId) -> Result<Testcase<I>, Error> {
self.inner.remove(idx) self.inner.remove(idx)