Skip to content

Commit

Permalink
chore: use &Path in FileRegistry::new_from_paths() (#594)
Browse files Browse the repository at this point in the history
  • Loading branch information
arendjr authored Jan 2, 2025
1 parent 50b976d commit 624a70a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions crates/core/src/problem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ use sha2::{Digest, Sha256};
use crate::api::FileMatchResult;
use std::{
collections::HashMap,
path::PathBuf,
path::{Path, PathBuf},
sync::mpsc::{self, Receiver, Sender},
};
use std::{fmt::Debug, str::FromStr};
Expand Down Expand Up @@ -268,7 +268,7 @@ impl Problem {
.iter()
.map(|f| PathBuf::from_str(&f.name()).unwrap())
.collect();
let borrowed_names: Vec<&PathBuf> = file_names.iter().collect();
let borrowed_names: Vec<&Path> = file_names.iter().map(PathBuf::as_path).collect();
let lazy_files: Vec<Box<dyn LoadableFile>> = files
.into_iter()
.map(|file| Box::new(file) as Box<dyn LoadableFile>)
Expand Down Expand Up @@ -538,7 +538,7 @@ impl Problem {
&self,
binding: FilePattern,
files: Vec<Box<dyn LoadableFile + 'a>>,
file_names: Vec<&PathBuf>,
file_names: Vec<&Path>,
owned_files: &FileOwners<Tree>,
context: &ExecutionContext,
) -> Result<Vec<MatchResult>> {
Expand Down
12 changes: 6 additions & 6 deletions crates/grit-pattern-matcher/src/pattern/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use grit_util::{
};
use rand::SeedableRng;
use std::ops::Range as StdRange;
use std::{collections::HashMap, path::PathBuf};
use std::{collections::HashMap, path::Path};

#[derive(Debug, Clone)]
pub struct EffectRange<'a, Q: QueryContext> {
Expand All @@ -37,7 +37,7 @@ pub struct FileRegistry<'a, Q: QueryContext> {
/// The number of versions for each file
version_count: Vec<u16>,
/// Original file paths, for lazy loading
file_paths: Vec<&'a PathBuf>,
file_paths: Vec<&'a Path>,
/// The actual FileOwner, which has the full file available
owners: Vec<Vec<&'a FileOwner<Q::Tree<'a>>>>,
}
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'a, Q: QueryContext> FileRegistry<'a, Q> {
self.owners[pointer.file as usize][pointer.version as usize]
}

pub fn get_file_name(&self, pointer: FilePtr) -> &'a PathBuf {
pub fn get_file_name(&self, pointer: FilePtr) -> &'a Path {
let file_index = pointer.file as usize;
let version_index = pointer.version as usize;
if let Some(owners) = self.owners.get(file_index) {
Expand All @@ -81,7 +81,7 @@ impl<'a, Q: QueryContext> FileRegistry<'a, Q> {
.expect("File path should exist for given file index.")
}

pub fn get_absolute_path(&self, pointer: FilePtr) -> GritResult<&'a PathBuf> {
pub fn get_absolute_path(&self, pointer: FilePtr) -> GritResult<&'a Path> {
let file_index = pointer.file as usize;
let version_index = pointer.version as usize;
if let Some(owners) = self.owners.get(file_index) {
Expand All @@ -95,8 +95,8 @@ impl<'a, Q: QueryContext> FileRegistry<'a, Q> {
}

/// If only the paths are available, create a FileRegistry with empty owners
/// This is *unsafe* if you do not later insert the appropriate owners before get_file_owner is called
pub fn new_from_paths(file_paths: Vec<&'a PathBuf>) -> Self {
/// This is a logic error if you do not later insert the appropriate owners before get_file_owner is called
pub fn new_from_paths(file_paths: Vec<&'a Path>) -> Self {
Self {
version_count: file_paths.iter().map(|_| 0).collect(),
owners: file_paths.iter().map(|_| Vec::new()).collect(),
Expand Down

0 comments on commit 624a70a

Please sign in to comment.