forked from M-Labs/zynq-rs
1
0
Fork 0

libconfig: fixed szl build.

to_lowercase would handle unicode which causes a huge increase in rodata
size, we have to use to_ascii_lowercase.
This commit is contained in:
pca006132 2020-11-04 20:47:40 +08:00
parent 0efc7a616f
commit d623913535
1 changed files with 4 additions and 4 deletions

View File

@ -56,9 +56,9 @@ fn parse_config<'a>(
buffer: &mut Vec<u8>, buffer: &mut Vec<u8>,
file: fatfs::File<sd_reader::SdReader>, file: fatfs::File<sd_reader::SdReader>,
) -> Result<'a, ()> { ) -> Result<'a, ()> {
let prefix = [key, "="].concat().to_lowercase(); let prefix = [key, "="].concat().to_ascii_lowercase();
for line in BufReader::new(file).lines() { for line in BufReader::new(file).lines() {
let line = line?.to_lowercase(); let line = line?.to_ascii_lowercase();
if line.starts_with(&prefix) { if line.starts_with(&prefix) {
buffer.extend(line[prefix.len()..].as_bytes()); buffer.extend(line[prefix.len()..].as_bytes());
return Ok(()); return Ok(());
@ -121,7 +121,7 @@ impl Config {
match root_dir.remove(&["/CONFIG/", key, ".BIN"].concat()) { match root_dir.remove(&["/CONFIG/", key, ".BIN"].concat()) {
Ok(()) => Ok(()), Ok(()) => Ok(()),
Err(_) => { Err(_) => {
let prefix = [key, "="].concat().to_lowercase(); let prefix = [key, "="].concat().to_ascii_lowercase();
match root_dir.create_file("/CONFIG.TXT") { match root_dir.create_file("/CONFIG.TXT") {
Ok(mut f) => { Ok(mut f) => {
let mut buffer = String::new(); let mut buffer = String::new();
@ -129,7 +129,7 @@ impl Config {
f.seek(SeekFrom::Start(0))?; f.seek(SeekFrom::Start(0))?;
f.truncate()?; f.truncate()?;
for line in buffer.lines() { for line in buffer.lines() {
if line.len() > 0 && !line.to_lowercase().starts_with(&prefix) { if line.len() > 0 && !line.to_ascii_lowercase().starts_with(&prefix) {
f.write(line.as_bytes())?; f.write(line.as_bytes())?;
f.write(NEWLINE)?; f.write(NEWLINE)?;
} }