Skip to content

Commit

Permalink
Remove as ref for buffer
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Apr 16, 2024
1 parent 8fde30d commit 5947f60
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 23 deletions.
4 changes: 2 additions & 2 deletions core/src/raw/adapters/kv/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<S: Adapter> oio::Write for KvWriter<S> {
}

async fn close(&mut self) -> Result<()> {
let buf = self.buffer.collect();
let buf = self.buffer.clone().collect();
self.kv.set(&self.path, buf).await
}

Expand All @@ -270,7 +270,7 @@ impl<S: Adapter> oio::BlockingWrite for KvWriter<S> {
}

fn close(&mut self) -> Result<()> {
let buf = self.buffer.collect();
let buf = self.buffer.clone().collect();
self.kv.blocking_set(&self.path, buf)?;
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions core/src/services/cacache/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,14 @@ impl kv::Adapter for Adapter {
}

async fn set(&self, path: &str, value: Buffer) -> Result<()> {
cacache::write(&self.datadir, path, value)
cacache::write(&self.datadir, path, value.to_vec())
.await
.map_err(parse_error)?;
Ok(())
}

fn blocking_set(&self, path: &str, value: Buffer) -> Result<()> {
cacache::write_sync(&self.datadir, path, value).map_err(parse_error)?;
cacache::write_sync(&self.datadir, path, value.to_vec()).map_err(parse_error)?;
Ok(())
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/d1/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ impl kv::Adapter for Adapter {
DO UPDATE SET {value_field} = EXCLUDED.{value_field}",
);

let params = vec![path.into(), value.as_ref().into()];
let params = vec![path.into(), value.to_vec().into()];
let req = self.create_d1_query_request(&query, params)?;

let resp = self.client.send(req).await?;
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/foundationdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl kv::Adapter for Adapter {
async fn set(&self, path: &str, value: Buffer) -> Result<()> {
let transaction = self.db.create_trx().expect("Unable to create transaction");

transaction.set(path.as_bytes(), value.as_ref());
transaction.set(path.as_bytes(), &value.to_vec());

match transaction.commit().await {
Ok(_) => Ok(()),
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/gridfs/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl kv::Adapter for Adapter {
// set new file
let mut upload_stream = bucket.open_upload_stream(path, None);
upload_stream
.write_all(value.as_ref())
.write_all(&value.to_vec())
.await
.map_err(new_std_io_error)?;
upload_stream.close().await.map_err(new_std_io_error)?;
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/memcached/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl kv::Adapter for Adapter {

conn.set(
&percent_encode_path(key),
value.as_ref(),
&value.to_vec(),
// Set expiration to 0 if ttl not set.
self.default_ttl
.map(|v| v.as_secs() as u32)
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/mysql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl kv::Adapter for Adapter {
statement,
params! {
"path" => path,
"value" => value.as_ref(),
"value" => value.to_vec(),
},
)
.await
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/persy/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ impl kv::Adapter for Adapter {
fn blocking_set(&self, path: &str, value: Buffer) -> Result<()> {
let mut tx = self.persy.begin().map_err(parse_error)?;
let id = tx
.insert(&self.segment, value.as_ref())
.insert(&self.segment, &value.to_vec())
.map_err(parse_error)?;

tx.put::<String, persy::PersyId>(&self.index, path.to_string(), id)
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/postgresql/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl kv::Adapter for Adapter {
.await
.map_err(parse_postgre_error)?;
let _ = connection
.query(&statement, &[&path, &value.as_ref()])
.query(&statement, &[&path, &value.to_vec()])
.await
.map_err(parse_postgre_error)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/redb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl kv::Adapter for Adapter {
.map_err(parse_table_error)?;

table
.insert(path, value.as_ref())
.insert(path, &*value.to_vec())
.map_err(parse_storage_error)?;
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/services/redis/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ impl kv::Adapter for Adapter {

async fn set(&self, key: &str, value: Buffer) -> Result<()> {
let conn = self.conn().await?;
let value = value.as_ref();
let value = value.to_vec();
match self.default_ttl {
Some(ttl) => match conn {
RedisConnection::Normal(mut conn) => conn
Expand Down
4 changes: 3 additions & 1 deletion core/src/services/rocksdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ impl kv::Adapter for Adapter {
}

fn blocking_set(&self, path: &str, value: Buffer) -> Result<()> {
self.db.put(path, value).map_err(parse_rocksdb_error)
self.db
.put(path, value.to_vec())
.map_err(parse_rocksdb_error)
}

async fn delete(&self, path: &str) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/sqlite/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl kv::Adapter for Adapter {
);
let mut statement = conn.prepare(&query).map_err(parse_rusqlite_error)?;
statement
.execute(params![path, value.as_ref()])
.execute(params![path, value.to_vec()])
.map_err(parse_rusqlite_error)?;
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/services/surrealdb/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ impl kv::Adapter for Adapter {
.await?
.query(query)
.bind(("path", path))
.bind(("value", value.as_ref()))
.bind(("value", value.to_vec()))
.await
.map_err(parse_surrealdb_error)?;
Ok(())
Expand Down
7 changes: 0 additions & 7 deletions core/src/types/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,6 @@ impl Default for Buffer {
Self::new()
}
}

impl AsRef<[u8]> for Buffer {
fn as_ref(&self) -> &[u8] {
self.chunk()
}
}

impl Buffer {
/// Create a new empty buffer.
///
Expand Down

0 comments on commit 5947f60

Please sign in to comment.