Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: parsing of constraints #254

Merged
merged 25 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions crates/rattler_conda_types/benches/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("parse complex version", |b| {
b.iter(|| black_box("1!1.0b2.post345.dev456+3.2.20.rc3").parse::<Version>())
});
c.bench_function("parse logical constraint", |b| {
b.iter(|| black_box(">=3.1").parse::<Version>())
});
c.bench_function("parse wildcard constraint", |b| {
b.iter(|| black_box("3.1.*").parse::<Version>())
});
c.bench_function("parse simple version spec", |b| {
b.iter(|| black_box(">=3.1").parse::<Version>())
});
c.bench_function("parse complex version spec", |b| {
b.iter(|| black_box("(>=2.1.0,<3.0)|(~=3.2.1,~3.2.2.1)|(==4.1)").parse::<Version>())
});
}

criterion_group!(benches, criterion_benchmark);
Expand Down
12 changes: 6 additions & 6 deletions crates/rattler_conda_types/src/version/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use smallvec::SmallVec;
pub use parse::{ParseVersionError, ParseVersionErrorKind};

mod flags;
mod parse;
pub(crate) mod parse;
mod segment;
mod with_source;

Expand Down Expand Up @@ -218,7 +218,7 @@ impl Version {
};
version_segments.iter().map(move |&segment| {
let start = idx;
idx += segment.len();
idx += segment.len() as usize;
SegmentIter {
offset: start,
version: self,
Expand Down Expand Up @@ -312,12 +312,12 @@ impl Version {
let mut idx = if self.has_epoch() { 1 } else { 0 };
idx += self.segments[..start]
.iter()
.map(|segment| segment.len())
.map(|segment| segment.len() as usize)
.sum::<usize>();
let version_segments = &self.segments[start..];
Either::Left(version_segments.iter().map(move |&segment| {
let start = idx;
idx += segment.len();
idx += segment.len() as usize;
SegmentIter {
offset: start,
version: self,
Expand Down Expand Up @@ -914,7 +914,7 @@ impl<'v> SegmentIter<'v> {
/// Returns the number of components stored in the version. Note that the number of components
/// returned by [`Self::components`] might differ because it might include an implicit default.
pub fn component_count(&self) -> usize {
self.segment.len()
self.segment.len() as usize
}

/// Returns an iterator over the components of this segment.
Expand All @@ -924,7 +924,7 @@ impl<'v> SegmentIter<'v> {
let version = self.version;

// Create an iterator over all component
let segment_components = (self.offset..self.offset + self.segment.len())
let segment_components = (self.offset..self.offset + self.segment.len() as usize)
.map(move |idx| &version.components[idx]);

// Add an implicit default if this segment has one
Expand Down
Loading