summaryrefslogtreecommitdiffstats
path: root/vendor/gix-attributes/src
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gix-attributes/src')
-rw-r--r--vendor/gix-attributes/src/lib.rs11
-rw-r--r--vendor/gix-attributes/src/name.rs10
-rw-r--r--vendor/gix-attributes/src/parse.rs5
-rw-r--r--vendor/gix-attributes/src/search/mod.rs6
-rw-r--r--vendor/gix-attributes/src/search/outcome.rs40
-rw-r--r--vendor/gix-attributes/src/state.rs28
6 files changed, 50 insertions, 50 deletions
diff --git a/vendor/gix-attributes/src/lib.rs b/vendor/gix-attributes/src/lib.rs
index c45b8f9f3..7eaac4282 100644
--- a/vendor/gix-attributes/src/lib.rs
+++ b/vendor/gix-attributes/src/lib.rs
@@ -8,8 +8,8 @@
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![deny(missing_docs, rust_2018_idioms, unsafe_code)]
-use byteyarn::{Yarn, YarnRef};
pub use gix_glob as glob;
+use kstring::{KString, KStringRef};
mod assignment;
///
@@ -34,6 +34,7 @@ pub fn parse(bytes: &[u8]) -> parse::Lines<'_> {
///
/// Note that this doesn't contain the name.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum StateRef<'a> {
/// The attribute is listed, or has the special value 'true'
Set,
@@ -41,6 +42,7 @@ pub enum StateRef<'a> {
Unset,
/// The attribute is set to the given value, which followed the `=` sign.
/// Note that values can be empty.
+ #[cfg_attr(feature = "serde", serde(borrow))]
Value(state::ValueRef<'a>),
/// The attribute isn't mentioned with a given path or is explicitly set to `Unspecified` using the `!` sign.
Unspecified,
@@ -50,6 +52,7 @@ pub enum StateRef<'a> {
///
/// Note that this doesn't contain the name.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum State {
/// The attribute is listed, or has the special value 'true'
Set,
@@ -64,14 +67,16 @@ pub enum State {
/// Represents a validated attribute name
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
-pub struct Name(pub(crate) Yarn);
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct Name(pub(crate) KString);
/// Holds a validated attribute name as a reference
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
-pub struct NameRef<'a>(YarnRef<'a, str>);
+pub struct NameRef<'a>(KStringRef<'a>);
/// Name an attribute and describe it's assigned state.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Assignment {
/// The validated name of the attribute.
pub name: Name,
diff --git a/vendor/gix-attributes/src/name.rs b/vendor/gix-attributes/src/name.rs
index 43a78bddb..40d86fd4c 100644
--- a/vendor/gix-attributes/src/name.rs
+++ b/vendor/gix-attributes/src/name.rs
@@ -1,16 +1,12 @@
use bstr::{BStr, BString, ByteSlice};
-use byteyarn::YarnRef;
+use kstring::KStringRef;
use crate::{Name, NameRef};
impl<'a> NameRef<'a> {
/// Turn this ref into its owned counterpart.
pub fn to_owned(self) -> Name {
- Name(
- self.0
- .immortalize()
- .map_or_else(|| self.0.to_boxed_str().into(), YarnRef::to_box),
- )
+ Name(self.0.into())
}
/// Return the inner `str`.
@@ -39,7 +35,7 @@ impl<'a> TryFrom<&'a BStr> for NameRef<'a> {
}
attr_valid(attr)
- .then(|| NameRef(YarnRef::from(attr.to_str().expect("no illformed utf8"))))
+ .then(|| NameRef(KStringRef::from_ref(attr.to_str().expect("no illformed utf8"))))
.ok_or_else(|| Error { attribute: attr.into() })
}
}
diff --git a/vendor/gix-attributes/src/parse.rs b/vendor/gix-attributes/src/parse.rs
index 7d8d6277a..2d90a006d 100644
--- a/vendor/gix-attributes/src/parse.rs
+++ b/vendor/gix-attributes/src/parse.rs
@@ -1,12 +1,13 @@
use std::borrow::Cow;
use bstr::{BStr, ByteSlice};
-use byteyarn::YarnRef;
+use kstring::KStringRef;
use crate::{name, AssignmentRef, Name, NameRef, StateRef};
/// The kind of attribute that was parsed.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Kind {
/// A pattern to match paths against
Pattern(gix_glob::Pattern),
@@ -75,7 +76,7 @@ fn check_attr(attr: &BStr) -> Result<NameRef<'_>, name::Error> {
}
attr_valid(attr)
- .then(|| NameRef(YarnRef::from(attr.to_str().expect("no illformed utf8"))))
+ .then(|| NameRef(KStringRef::from_ref(attr.to_str().expect("no illformed utf8"))))
.ok_or_else(|| name::Error { attribute: attr.into() })
}
diff --git a/vendor/gix-attributes/src/search/mod.rs b/vendor/gix-attributes/src/search/mod.rs
index f06928bf2..83c6d4192 100644
--- a/vendor/gix-attributes/src/search/mod.rs
+++ b/vendor/gix-attributes/src/search/mod.rs
@@ -1,6 +1,6 @@
use std::collections::HashMap;
-use byteyarn::Yarn;
+use kstring::KString;
use smallvec::SmallVec;
use crate::{Assignment, AssignmentRef};
@@ -99,7 +99,7 @@ pub struct Outcome {
/// A stack of attributes to use for processing attributes of matched patterns and for resolving their macros.
attrs_stack: SmallVec<[(AttributeId, Assignment, Option<AttributeId>); 8]>,
/// A set of attributes we should limit ourselves to, or empty if we should fill in all attributes, made of
- selected: SmallVec<[(Yarn, Option<AttributeId>); AVERAGE_NUM_ATTRS]>,
+ selected: SmallVec<[(KString, Option<AttributeId>); AVERAGE_NUM_ATTRS]>,
/// storage for all patterns we have matched so far (in order to avoid referencing them, we copy them, but only once).
patterns: RefMap<gix_glob::Pattern>,
/// storage for all assignments we have matched so far (in order to avoid referencing them, we copy them, but only once).
@@ -135,7 +135,7 @@ pub struct MetadataCollection {
/// A mapping of an attribute or macro name to its order, that is the time when it was *first* seen.
///
/// This is the inverse of the order attributes are searched.
- name_to_meta: HashMap<Yarn, Metadata>,
+ name_to_meta: HashMap<KString, Metadata>,
}
/// Metadata associated with an attribute or macro name.
diff --git a/vendor/gix-attributes/src/search/outcome.rs b/vendor/gix-attributes/src/search/outcome.rs
index 9ad8a81e1..7cea3bd19 100644
--- a/vendor/gix-attributes/src/search/outcome.rs
+++ b/vendor/gix-attributes/src/search/outcome.rs
@@ -1,6 +1,6 @@
use bstr::{BString, ByteSlice};
-use byteyarn::Yarn;
use gix_glob::Pattern;
+use kstring::{KString, KStringRef};
use crate::{
search::{
@@ -44,7 +44,7 @@ impl Outcome {
pub fn initialize_with_selection<'a>(
&mut self,
collection: &MetadataCollection,
- attribute_names: impl IntoIterator<Item = impl Into<&'a str>>,
+ attribute_names: impl IntoIterator<Item = impl Into<KStringRef<'a>>>,
) {
self.initialize_with_selection_inner(collection, &mut attribute_names.into_iter().map(Into::into))
}
@@ -52,15 +52,15 @@ impl Outcome {
fn initialize_with_selection_inner(
&mut self,
collection: &MetadataCollection,
- attribute_names: &mut dyn Iterator<Item = &str>,
+ attribute_names: &mut dyn Iterator<Item = KStringRef<'_>>,
) {
self.initialize(collection);
self.selected.clear();
self.selected.extend(attribute_names.map(|name| {
(
- Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
- collection.name_to_meta.get(name).map(|meta| meta.id),
+ name.to_owned(),
+ collection.name_to_meta.get(name.as_str()).map(|meta| meta.id),
)
}));
self.reset_remaining();
@@ -176,12 +176,11 @@ impl Outcome {
source: Option<&std::path::PathBuf>,
sequence_number: usize,
) -> bool {
- self.attrs_stack.extend(attrs.filter_map(|attr| {
- self.matches_by_id[attr.id.0]
- .r#match
- .is_none()
- .then(|| (attr.id, attr.inner.clone(), None))
- }));
+ self.attrs_stack.extend(
+ attrs
+ .filter(|attr| self.matches_by_id[attr.id.0].r#match.is_none())
+ .map(|attr| (attr.id, attr.inner.clone(), None)),
+ );
while let Some((id, assignment, parent_order)) = self.attrs_stack.pop() {
let slot = &mut self.matches_by_id[id.0];
if slot.r#match.is_some() {
@@ -212,12 +211,12 @@ impl Outcome {
if is_macro {
// TODO(borrowchk): one fine day we should be able to re-borrow `slot` without having to redo the array access.
let slot = &self.matches_by_id[id.0];
- self.attrs_stack.extend(slot.macro_attributes.iter().filter_map(|attr| {
- self.matches_by_id[attr.id.0]
- .r#match
- .is_none()
- .then(|| (attr.id, attr.inner.clone(), Some(id)))
- }));
+ self.attrs_stack.extend(
+ slot.macro_attributes
+ .iter()
+ .filter(|attr| self.matches_by_id[attr.id.0].r#match.is_none())
+ .map(|attr| (attr.id, attr.inner.clone(), Some(id))),
+ );
}
}
false
@@ -315,7 +314,7 @@ impl MetadataCollection {
None => {
let order = AttributeId(self.name_to_meta.len());
self.name_to_meta.insert(
- Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
+ KString::from_ref(name),
Metadata {
id: order,
macro_attributes: Default::default(),
@@ -335,10 +334,7 @@ impl MetadataCollection {
Some(meta) => meta.id,
None => {
let order = AttributeId(self.name_to_meta.len());
- self.name_to_meta.insert(
- Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
- order.into(),
- );
+ self.name_to_meta.insert(KString::from_ref(name), order.into());
order
}
}
diff --git a/vendor/gix-attributes/src/state.rs b/vendor/gix-attributes/src/state.rs
index 585e05adc..80ebcfead 100644
--- a/vendor/gix-attributes/src/state.rs
+++ b/vendor/gix-attributes/src/state.rs
@@ -1,21 +1,29 @@
use bstr::{BStr, ByteSlice};
-use byteyarn::{ByteYarn, YarnRef};
+use kstring::{KString, KStringRef};
use crate::{State, StateRef};
/// A container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone)]
-pub struct Value(ByteYarn);
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct Value(KString);
/// A reference container to encapsulate a tightly packed and typically unallocated byte value that isn't necessarily UTF8 encoded.
#[derive(PartialEq, Eq, Debug, Hash, Ord, PartialOrd, Clone, Copy)]
-pub struct ValueRef<'a>(YarnRef<'a, [u8]>);
+#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
+pub struct ValueRef<'a>(#[cfg_attr(feature = "serde", serde(borrow))] KStringRef<'a>);
/// Lifecycle
impl<'a> ValueRef<'a> {
/// Keep `input` as our value.
pub fn from_bytes(input: &'a [u8]) -> Self {
- Self(YarnRef::from(input))
+ Self(KStringRef::from_ref(
+ // SAFETY: our API makes accessing that value as `str` impossible, so illformed UTF8 is never exposed as such.
+ #[allow(unsafe_code)]
+ unsafe {
+ std::str::from_utf8_unchecked(input)
+ },
+ ))
}
}
@@ -34,25 +42,19 @@ impl ValueRef<'_> {
impl<'a> From<&'a str> for ValueRef<'a> {
fn from(v: &'a str) -> Self {
- ValueRef(v.as_bytes().into())
+ ValueRef(v.into())
}
}
impl<'a> From<ValueRef<'a>> for Value {
fn from(v: ValueRef<'a>) -> Self {
- Value(
- v.0.immortalize()
- .map_or_else(|| v.0.to_boxed_bytes().into(), YarnRef::to_box),
- )
+ Value(v.0.into())
}
}
impl From<&str> for Value {
fn from(v: &str) -> Self {
- Value(
- ByteYarn::inlined(v.as_bytes())
- .unwrap_or_else(|| ByteYarn::from_boxed_bytes(v.as_bytes().to_vec().into_boxed_slice())),
- )
+ Value(KString::from_ref(v))
}
}