mirror of
https://github.com/sxyazi/yazi.git
synced 2026-07-24 00:01:03 +00:00
perf: accelerate kitty graphics protocol encoding by avoiding string reallocation (#837)
This commit is contained in:
parent
9ba47141bf
commit
f8e0aee311
2 changed files with 8 additions and 6 deletions
|
|
@ -1,3 +1,4 @@
|
|||
use core::str;
|
||||
use std::{io::{stderr, BufWriter, Write}, path::Path};
|
||||
|
||||
use anyhow::Result;
|
||||
|
|
@ -344,7 +345,7 @@ impl Kitty {
|
|||
|
||||
async fn encode(img: DynamicImage) -> Result<Vec<u8>> {
|
||||
fn output(raw: &[u8], format: u8, size: (u32, u32)) -> Result<Vec<u8>> {
|
||||
let b64: Vec<_> = general_purpose::STANDARD.encode(raw).chars().collect();
|
||||
let b64 = general_purpose::STANDARD.encode(raw).into_bytes();
|
||||
|
||||
let mut it = b64.chunks(4096).peekable();
|
||||
let mut buf = Vec::with_capacity(b64.len() + it.len() * 50);
|
||||
|
|
@ -357,7 +358,7 @@ impl Kitty {
|
|||
size.0,
|
||||
size.1,
|
||||
it.peek().is_some() as u8,
|
||||
first.iter().collect::<String>(),
|
||||
unsafe { str::from_utf8_unchecked(first) },
|
||||
ESCAPE,
|
||||
CLOSE
|
||||
)?;
|
||||
|
|
@ -369,7 +370,7 @@ impl Kitty {
|
|||
"{}_Gm={};{}{}\\{}",
|
||||
START,
|
||||
it.peek().is_some() as u8,
|
||||
chunk.iter().collect::<String>(),
|
||||
unsafe { str::from_utf8_unchecked(chunk) },
|
||||
ESCAPE,
|
||||
CLOSE
|
||||
)?;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use core::str;
|
||||
use std::{io::{stderr, Write}, path::Path};
|
||||
|
||||
use anyhow::Result;
|
||||
|
|
@ -35,7 +36,7 @@ impl KittyOld {
|
|||
|
||||
async fn encode(img: DynamicImage) -> Result<Vec<u8>> {
|
||||
fn output(raw: &[u8], format: u8, size: (u32, u32)) -> Result<Vec<u8>> {
|
||||
let b64: Vec<_> = general_purpose::STANDARD.encode(raw).chars().collect();
|
||||
let b64 = general_purpose::STANDARD.encode(raw).into_bytes();
|
||||
|
||||
let mut it = b64.chunks(4096).peekable();
|
||||
let mut buf = Vec::with_capacity(b64.len() + it.len() * 50);
|
||||
|
|
@ -48,7 +49,7 @@ impl KittyOld {
|
|||
size.0,
|
||||
size.1,
|
||||
it.peek().is_some() as u8,
|
||||
first.iter().collect::<String>(),
|
||||
unsafe { str::from_utf8_unchecked(first) },
|
||||
ESCAPE,
|
||||
CLOSE
|
||||
)?;
|
||||
|
|
@ -60,7 +61,7 @@ impl KittyOld {
|
|||
"{}_Gm={};{}{}\\{}",
|
||||
START,
|
||||
it.peek().is_some() as u8,
|
||||
chunk.iter().collect::<String>(),
|
||||
unsafe { str::from_utf8_unchecked(chunk) },
|
||||
ESCAPE,
|
||||
CLOSE
|
||||
)?;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue