refactor: Prefer mutable slices over a mutable Vec

We never add anything to the collection, so don't allow for the
possibility.
pull/24376/head
Jake Goulding 2020-02-21 09:01:32 -05:00
parent 3afb2c6c70
commit 7620adfc70
4 changed files with 9 additions and 9 deletions

View File

@ -29,12 +29,12 @@ impl Database {
&self,
_org_id: u32,
bucket: &Bucket,
points: &mut Vec<PointType>,
points: &mut [PointType],
) -> Result<(), StorageError> {
self.local_index
.get_or_create_series_ids_for_points(bucket.id, points)?;
self.local_series_store
.write_points_with_series_ids(bucket.id, &points)
.write_points_with_series_ids(bucket.id, points)
}
pub fn get_bucket_by_name(

View File

@ -6,7 +6,7 @@ pub trait InvertedIndex: Sync + Send {
fn get_or_create_series_ids_for_points(
&self,
bucket_id: u32,
points: &mut Vec<PointType>,
points: &mut [PointType],
) -> Result<(), StorageError>;
fn read_series_matching(

View File

@ -238,7 +238,7 @@ impl MemDB {
fn get_or_create_series_ids_for_points(
&self,
bucket_id: u32,
points: &mut Vec<PointType>,
points: &mut [PointType],
) -> Result<(), StorageError> {
// first try to do everything with just a read lock
if self.get_series_ids_for_points(bucket_id, points) {
@ -269,7 +269,7 @@ impl MemDB {
// get_series_ids_for_points attempts to fill the series ids for all points in the passed in
// collection using only a read lock. If no SeriesMap exists for the bucket, it will be inserted.
// It will return true if all points have series ids filled in.
fn get_series_ids_for_points(&self, bucket_id: u32, points: &mut Vec<PointType>) -> bool {
fn get_series_ids_for_points(&self, bucket_id: u32, points: &mut [PointType]) -> bool {
let buckets = self.bucket_id_to_series_map.read().unwrap();
match buckets.get(&bucket_id) {
Some(b) => {
@ -578,7 +578,7 @@ impl InvertedIndex for MemDB {
fn get_or_create_series_ids_for_points(
&self,
bucket_id: u32,
points: &mut Vec<PointType>,
points: &mut [PointType],
) -> Result<(), StorageError> {
self.get_or_create_series_ids_for_points(bucket_id, points)
}

View File

@ -246,7 +246,7 @@ impl RocksDB {
pub fn get_series_ids(
&self,
bucket_id: u32,
points: &mut Vec<PointType>,
points: &mut [PointType],
) -> Result<(), StorageError> {
let cf_name = index_cf_name(bucket_id);
@ -513,7 +513,7 @@ impl RocksDB {
// TODO: build the index for levels other than the first
// insert_series_without_ids will insert any series into the index and obtain an identifier for it.
// the passed in series vector is modified so that the newly inserted series have their ids
pub fn insert_series_without_ids(&self, bucket_id: u32, points: &mut Vec<PointType>) {
pub fn insert_series_without_ids(&self, bucket_id: u32, points: &mut [PointType]) {
// We want to get a lock on new series only for this bucket
self.ensure_series_mutex_exists(bucket_id);
let map = self.series_insert_lock.read().expect("mutex poisoned");
@ -744,7 +744,7 @@ impl InvertedIndex for RocksDB {
fn get_or_create_series_ids_for_points(
&self,
bucket_id: u32,
points: &mut Vec<PointType>,
points: &mut [PointType],
) -> Result<(), StorageError> {
self.get_series_ids(bucket_id, points)?;
self.insert_series_without_ids(bucket_id, points);