Remove some AsRef<str> (#3354)

Using &str instead of AsRef is better for compile times, binary size and code complexity.
This commit is contained in:
Hocuri
2022-05-23 12:57:50 +02:00
committed by GitHub
parent 9c41f0fdb9
commit 9549aca48b
10 changed files with 25 additions and 36 deletions

View File

@@ -786,7 +786,7 @@ impl ChatId {
);
let row = sql
.query_row_optional(
query,
&query,
paramsv![
self,
MessageState::OutPreparing,
@@ -3061,7 +3061,7 @@ pub async fn forward_msgs(context: &Context, msg_ids: &[MsgId], chat_id: ChatId)
let ids = context
.sql
.query_map(
format!(
&format!(
"SELECT id FROM msgs WHERE id IN({}) ORDER BY timestamp,id",
sql::repeat_vars(msg_ids.len())
),

View File

@@ -699,7 +699,7 @@ impl Contact {
context
.sql
.query_map(
format!(
&format!(
"SELECT c.id FROM contacts c \
LEFT JOIN acpeerstates ps ON c.addr=ps.addr \
WHERE c.addr NOT IN ({})
@@ -754,7 +754,7 @@ impl Contact {
context
.sql
.query_map(
format!(
&format!(
"SELECT id FROM contacts
WHERE addr NOT IN ({})
AND id>?

View File

@@ -2008,7 +2008,7 @@ async fn check_verified_properties(
let rows = context
.sql
.query_map(
format!(
&format!(
"SELECT c.addr, LENGTH(ps.verified_key_fingerprint) FROM contacts c \
LEFT JOIN acpeerstates ps ON c.addr=ps.addr WHERE c.id IN({}) ",
sql::repeat_vars(to_ids.len())

View File

@@ -307,7 +307,7 @@ pub(crate) async fn start_ephemeral_timers_msgids(
let count = context
.sql
.execute(
format!(
&format!(
"UPDATE msgs SET ephemeral_timestamp = ? + ephemeral_timer
WHERE (ephemeral_timestamp == 0 OR ephemeral_timestamp > ? + ephemeral_timer) AND ephemeral_timer > 0
AND id IN ({})",

View File

@@ -910,7 +910,7 @@ impl Imap {
context
.sql
.execute(
format!(
&format!(
"DELETE FROM imap WHERE id IN ({})",
sql::repeat_vars(row_ids.len())
),
@@ -947,7 +947,7 @@ impl Imap {
context
.sql
.execute(
format!(
&format!(
"DELETE FROM imap WHERE id IN ({})",
sql::repeat_vars(row_ids.len())
),
@@ -989,7 +989,7 @@ impl Imap {
context
.sql
.execute(
format!(
&format!(
"UPDATE imap SET target='' WHERE id IN ({})",
sql::repeat_vars(row_ids.len())
),
@@ -1106,7 +1106,7 @@ impl Imap {
context
.sql
.execute(
format!(
&format!(
"DELETE FROM imap_markseen WHERE id IN ({})",
sql::repeat_vars(rowid_set.len())
),

View File

@@ -1283,7 +1283,7 @@ pub async fn markseen_msgs(context: &Context, msg_ids: Vec<MsgId>) -> Result<()>
let msgs = context
.sql
.query_map(
format!(
&format!(
"SELECT
m.id AS id,
m.chat_id AS chat_id,

View File

@@ -593,7 +593,7 @@ async fn send_mdn_msg_id(
);
context
.sql
.execute(q, rusqlite::params_from_iter(additional_msg_ids))
.execute(&q, rusqlite::params_from_iter(additional_msg_ids))
.await?;
}
Ok(())

View File

@@ -331,24 +331,16 @@ impl Sql {
}
/// Execute the given query, returning the number of affected rows.
pub async fn execute(
&self,
query: impl AsRef<str>,
params: impl rusqlite::Params,
) -> Result<usize> {
pub async fn execute(&self, query: &str, params: impl rusqlite::Params) -> Result<usize> {
let conn = self.get_conn().await?;
let res = conn.execute(query.as_ref(), params)?;
let res = conn.execute(query, params)?;
Ok(res)
}
/// Executes the given query, returning the last inserted row ID.
pub async fn insert(
&self,
query: impl AsRef<str>,
params: impl rusqlite::Params,
) -> Result<i64> {
pub async fn insert(&self, query: &str, params: impl rusqlite::Params) -> Result<i64> {
let conn = self.get_conn().await?;
conn.execute(query.as_ref(), params)?;
conn.execute(query, params)?;
Ok(conn.last_insert_rowid())
}
@@ -357,7 +349,7 @@ impl Sql {
/// result of that function.
pub async fn query_map<T, F, G, H>(
&self,
sql: impl AsRef<str>,
sql: &str,
params: impl rusqlite::Params,
f: F,
mut g: G,
@@ -366,8 +358,6 @@ impl Sql {
F: FnMut(&rusqlite::Row) -> rusqlite::Result<T>,
G: FnMut(rusqlite::MappedRows<F>) -> Result<H>,
{
let sql = sql.as_ref();
let conn = self.get_conn().await?;
let mut stmt = conn.prepare(sql)?;
let res = stmt.query_map(params, f)?;
@@ -385,11 +375,7 @@ impl Sql {
}
/// Used for executing `SELECT COUNT` statements only. Returns the resulting count.
pub async fn count(
&self,
query: impl AsRef<str>,
params: impl rusqlite::Params,
) -> anyhow::Result<usize> {
pub async fn count(&self, query: &str, params: impl rusqlite::Params) -> anyhow::Result<usize> {
let count: isize = self.query_row(query, params, |row| row.get(0)).await?;
Ok(usize::try_from(count)?)
}
@@ -404,7 +390,7 @@ impl Sql {
/// Execute a query which is expected to return one row.
pub async fn query_row<T, F>(
&self,
query: impl AsRef<str>,
query: &str,
params: impl rusqlite::Params,
f: F,
) -> Result<T>
@@ -412,7 +398,7 @@ impl Sql {
F: FnOnce(&rusqlite::Row) -> rusqlite::Result<T>,
{
let conn = self.get_conn().await?;
let res = conn.query_row(query.as_ref(), params, f)?;
let res = conn.query_row(query, params, f)?;
Ok(res)
}
@@ -474,7 +460,7 @@ impl Sql {
/// Execute a query which is expected to return zero or one row.
pub async fn query_row_optional<T, F>(
&self,
sql: impl AsRef<str>,
sql: &str,
params: impl rusqlite::Params,
f: F,
) -> anyhow::Result<Option<T>>

View File

@@ -199,7 +199,7 @@ impl Context {
pub(crate) async fn delete_sync_ids(&self, ids: String) -> Result<()> {
self.sql
.execute(
format!("DELETE FROM multi_device_sync WHERE id IN ({});", ids),
&format!("DELETE FROM multi_device_sync WHERE id IN ({});", ids),
paramsv![],
)
.await?;