mirror of
https://github.com/edu4rdshl/Strata.git
synced 2026-07-17 23:24:46 +00:00
perf: eliminate unnecessary clones in write_to_clipboard
write_to_clipboard took ownership of WriteRequest but immediately cloned both fields into locals, then cloned bytes again for the text path -- three heap allocations on a potentially large byte buffer. Destructure the owned request directly and move the fields. The text path still needs one clone (bytes goes into two MimeSources), but the extra upfront clones are gone. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
64d5bbfdc3
commit
eb64476a2a
1 changed files with 5 additions and 3 deletions
|
|
@ -12,8 +12,10 @@ pub struct WriteRequest {
|
|||
}
|
||||
|
||||
pub fn write_to_clipboard(req: WriteRequest) -> Result<()> {
|
||||
let mime = req.mime_type.clone();
|
||||
let bytes = req.content.clone();
|
||||
let WriteRequest {
|
||||
mime_type: mime,
|
||||
content: bytes,
|
||||
} = req;
|
||||
|
||||
// For text, offer both the specific type and text/plain for compatibility.
|
||||
let sources: Vec<MimeSource> = if mime.starts_with("text/") {
|
||||
|
|
@ -23,7 +25,7 @@ pub fn write_to_clipboard(req: WriteRequest) -> Result<()> {
|
|||
mime_type: MimeType::Specific(mime.clone()),
|
||||
},
|
||||
MimeSource {
|
||||
source: Source::Bytes(bytes.clone().into()),
|
||||
source: Source::Bytes(bytes.into()),
|
||||
mime_type: MimeType::Specific("text/plain;charset=utf-8".into()),
|
||||
},
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue