Skip to content

Commit

Permalink
rename SmallVec to CowVec
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Dec 19, 2024
1 parent 121a557 commit f757dec
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 26 deletions.
3 changes: 1 addition & 2 deletions src/jsr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::package::PackageReq;
use crate::package::PackageReqParseError;
use crate::package::PackageReqReference;
use crate::package::PackageReqReferenceParseError;
use crate::StackString;

/// A reference to a JSR package's name, version constraint, and potential sub path.
/// This contains all the information found in an npm specifier.
Expand Down Expand Up @@ -270,7 +269,7 @@ impl JsrDepPackageReq {
/// Outputs a normalized string representation of this dependency.
///
/// Note: The normalized string is not safe for a URL. It's best used for serialization.
pub fn to_string_normalized(&self) -> StackString {
pub fn to_string_normalized(&self) -> crate::StackString {
capacity_builder::StringBuilder::build(|builder| {
builder.append(self.kind.scheme_with_colon());
builder.append(&self.req.name);
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod specifier;
mod string;

/// A smaller two-byte vector.
pub type SmallVec<T> = ecow::EcoVec<T>;
pub type CowVec<T> = ecow::EcoVec<T>;
pub use string::SmallStackString;
pub use string::StackString;

Expand Down Expand Up @@ -58,8 +58,8 @@ pub struct Version {
pub major: u64,
pub minor: u64,
pub patch: u64,
pub pre: SmallVec<VersionPreOrBuild>,
pub build: SmallVec<VersionPreOrBuild>,
pub pre: CowVec<VersionPreOrBuild>,
pub build: CowVec<VersionPreOrBuild>,
}

impl<'a> StringAppendable<'a> for &'a Version {
Expand Down
18 changes: 9 additions & 9 deletions src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::package::PackageReq;
use crate::package::PackageReqReference;
use crate::package::PackageReqReferenceParseError;
use crate::PackageTag;
use crate::SmallVec;
use crate::CowVec;
use crate::VersionPreOrBuild;

use super::Partial;
Expand Down Expand Up @@ -138,7 +138,7 @@ fn inner(input: &str) -> ParseResult<RangeSetOrTag> {
if input.is_empty() {
return Ok((
input,
RangeSetOrTag::RangeSet(VersionRangeSet(SmallVec::from([
RangeSetOrTag::RangeSet(VersionRangeSet(CowVec::from([
VersionRange::all(),
]))),
));
Expand Down Expand Up @@ -169,7 +169,7 @@ fn inner(input: &str) -> ParseResult<RangeSetOrTag> {
let ranges = ranges
.into_iter()
.filter_map(|r| r.into_range())
.collect::<SmallVec<_>>();
.collect::<CowVec<_>>();
Ok((input, RangeSetOrTag::RangeSet(VersionRangeSet(ranges))))
}

Expand Down Expand Up @@ -445,8 +445,8 @@ fn nr(input: &str) -> ParseResult<u64> {

#[derive(Debug, Clone, Default)]
struct Qualifier {
pre: SmallVec<VersionPreOrBuild>,
build: SmallVec<VersionPreOrBuild>,
pre: CowVec<VersionPreOrBuild>,
build: CowVec<VersionPreOrBuild>,
}

// qualifier ::= ( '-' pre )? ( '+' build )?
Expand All @@ -463,23 +463,23 @@ fn qualifier(input: &str) -> ParseResult<Qualifier> {
}

// pre ::= parts
fn pre(input: &str) -> ParseResult<SmallVec<VersionPreOrBuild>> {
fn pre(input: &str) -> ParseResult<CowVec<VersionPreOrBuild>> {
preceded(maybe(ch('-')), parts)(input)
}

// build ::= parts
fn build(input: &str) -> ParseResult<SmallVec<VersionPreOrBuild>> {
fn build(input: &str) -> ParseResult<CowVec<VersionPreOrBuild>> {
preceded(ch('+'), parts)(input)
}

// parts ::= part ( '.' part ) *
fn parts(input: &str) -> ParseResult<SmallVec<VersionPreOrBuild>> {
fn parts(input: &str) -> ParseResult<CowVec<VersionPreOrBuild>> {
if_true(
map(separated_list(part, ch('.')), |text| {
text
.into_iter()
.map(VersionPreOrBuild::from_str)
.collect::<SmallVec<_>>()
.collect::<CowVec<_>>()
}),
|items| !items.is_empty(),
)(input)
Expand Down
8 changes: 4 additions & 4 deletions src/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use capacity_builder::StringType;
use serde::Deserialize;
use serde::Serialize;

use crate::SmallVec;
use crate::CowVec;
use crate::VersionPreOrBuild;

use super::Version;
Expand All @@ -18,7 +18,7 @@ use super::Version;
#[derive(
Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, CapacityDisplay,
)]
pub struct VersionRangeSet(pub SmallVec<VersionRange>);
pub struct VersionRangeSet(pub CowVec<VersionRange>);

impl VersionRangeSet {
pub fn satisfies(&self, version: &Version) -> bool {
Expand Down Expand Up @@ -511,8 +511,8 @@ pub struct Partial {
pub major: XRange,
pub minor: XRange,
pub patch: XRange,
pub pre: SmallVec<VersionPreOrBuild>,
pub build: SmallVec<VersionPreOrBuild>,
pub pre: CowVec<VersionPreOrBuild>,
pub build: CowVec<VersionPreOrBuild>,
}

impl Partial {
Expand Down
16 changes: 8 additions & 8 deletions src/specifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::range::VersionRangeSet;
use crate::range::XRange;
use crate::PackageTag;
use crate::RangeSetOrTag;
use crate::SmallVec;
use crate::CowVec;
use crate::VersionPreOrBuild;
use crate::VersionReq;

Expand Down Expand Up @@ -39,7 +39,7 @@ pub fn parse_version_req_from_specifier(
crate::SmallStackString::from_str(input),
match range_result {
Ok(range) => {
RangeSetOrTag::RangeSet(VersionRangeSet(SmallVec::from([range])))
RangeSetOrTag::RangeSet(VersionRangeSet(CowVec::from([range])))
}
Err(err) => {
if is_valid_tag(input) {
Expand Down Expand Up @@ -136,8 +136,8 @@ fn nr(input: &str) -> ParseResult<u64> {

#[derive(Debug, Clone, Default)]
struct Qualifier {
pre: SmallVec<VersionPreOrBuild>,
build: SmallVec<VersionPreOrBuild>,
pre: CowVec<VersionPreOrBuild>,
build: CowVec<VersionPreOrBuild>,
}

// qualifier ::= ( '-' pre )? ( '+' build )?
Expand All @@ -154,23 +154,23 @@ fn qualifier(input: &str) -> ParseResult<Qualifier> {
}

// pre ::= parts
fn pre(input: &str) -> ParseResult<SmallVec<VersionPreOrBuild>> {
fn pre(input: &str) -> ParseResult<CowVec<VersionPreOrBuild>> {
preceded(ch('-'), parts)(input)
}

// build ::= parts
fn build(input: &str) -> ParseResult<SmallVec<VersionPreOrBuild>> {
fn build(input: &str) -> ParseResult<CowVec<VersionPreOrBuild>> {
preceded(ch('+'), parts)(input)
}

// parts ::= part ( '.' part ) *
fn parts(input: &str) -> ParseResult<SmallVec<VersionPreOrBuild>> {
fn parts(input: &str) -> ParseResult<CowVec<VersionPreOrBuild>> {
if_true(
map(separated_list(part, ch('.')), |text| {
text
.into_iter()
.map(VersionPreOrBuild::from_str)
.collect::<SmallVec<_>>()
.collect::<CowVec<_>>()
}),
|items| !items.is_empty(),
)(input)
Expand Down

0 comments on commit f757dec

Please sign in to comment.