Skip to content

Commit

Permalink
Use indexmap to speedup if an element is in a vector
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Apr 26, 2024
1 parent 2092680 commit 8998c5a
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 257 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

.vscode/
!.vscode/extensions.json

perf.data
perf.data.old
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions slinky/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ edition = "2021"
serde = {version="1.0.197", features = ["derive"]}
serde_yaml = "0.9.32"
thiserror = "1.0.57"
indexmap = "2.2.6"

[dev-dependencies]
rstest = "0.18.2"
23 changes: 11 additions & 12 deletions slinky/src/linker_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
/* SPDX-License-Identifier: MIT */

use std::path::PathBuf;
use std::{collections::HashSet, io::Write, path::Path};
use std::{io::Write, path::Path};

use crate::{file_kind::FileKind, SlinkyError};
use crate::{utils, Settings};
use crate::{FileInfo, Segment};

pub struct LinkerWriter<'a> {
linker_symbols: HashSet<String>,
linker_symbols: indexmap::IndexSet<String>,

// Used for dependency generation
files_paths: Vec<PathBuf>,
files_paths: indexmap::IndexSet<PathBuf>,

indent_level: i32,
buffer: Vec<String>,
Expand All @@ -25,8 +25,8 @@ pub struct LinkerWriter<'a> {
impl<'a> LinkerWriter<'a> {
pub fn new(settings: &'a Settings) -> Self {
Self {
linker_symbols: HashSet::new(),
files_paths: Vec::new(),
linker_symbols: indexmap::IndexSet::new(),
files_paths: indexmap::IndexSet::new(),
indent_level: 0,
buffer: Vec::new(),

Expand Down Expand Up @@ -380,10 +380,7 @@ impl<'a> LinkerWriter<'a> {
""
};

let mut linker_symbols_sorted: Vec<_> = self.linker_symbols.iter().collect();
linker_symbols_sorted.sort();

for sym in linker_symbols_sorted {
for sym in &self.linker_symbols {
if let Err(e) = writeln!(
f,
"extern {} {}{};",
Expand Down Expand Up @@ -455,7 +452,7 @@ impl LinkerWriter<'_> {
// Getters / Setters
impl LinkerWriter<'_> {
#[must_use]
pub fn get_linker_symbols(&self) -> &HashSet<String> {
pub fn get_linker_symbols(&self) -> &indexmap::IndexSet<String> {
&self.linker_symbols
}
}
Expand Down Expand Up @@ -570,7 +567,8 @@ impl LinkerWriter<'_> {

self.writeln(&format!("{}({}{});", path.display(), section, wildcard));
if !self.files_paths.contains(&path) {
self.files_paths.push(path);
//self.files_paths.push(path);
self.files_paths.insert(path);
}
}
FileKind::Archive => {
Expand All @@ -585,7 +583,8 @@ impl LinkerWriter<'_> {
wildcard
));
if !self.files_paths.contains(&path) {
self.files_paths.push(path);
//self.files_paths.push(path);
self.files_paths.insert(path);
}
}
FileKind::Pad => {
Expand Down
150 changes: 75 additions & 75 deletions tests/partial_linking/follow_segment.h
Original file line number Diff line number Diff line change
@@ -1,113 +1,113 @@
#ifndef HEADER_SYMBOLS_H
#define HEADER_SYMBOLS_H

extern char bootCOMMON_END[];
extern char bootCOMMON_SIZE[];
extern char bootCOMMON_START[];
extern char boot_BSS_END[];
extern char boot_BSS_SIZE[];
extern char boot_BSS_START[];
extern char boot_ROM_START[];
extern char boot_VRAM[];
extern char boot_alloc_VRAM[];
extern char boot_TEXT_START[];
extern char boot_TEXT_END[];
extern char boot_TEXT_SIZE[];
extern char boot_DATA_START[];
extern char boot_DATA_END[];
extern char boot_DATA_SIZE[];
extern char boot_DATA_START[];
extern char boot_RODATA_START[];
extern char boot_RODATA_END[];
extern char boot_RODATA_SIZE[];
extern char boot_RODATA_START[];
extern char boot_ROM_END[];
extern char boot_ROM_SIZE[];
extern char boot_ROM_START[];
extern char boot_SBSS_END[];
extern char boot_SBSS_SIZE[];
extern char boot_SBSS_START[];
extern char boot_SCOMMON_END[];
extern char boot_SCOMMON_SIZE[];
extern char boot_SCOMMON_START[];
extern char boot_SDATA_START[];
extern char boot_SDATA_END[];
extern char boot_SDATA_SIZE[];
extern char boot_SDATA_START[];
extern char boot_TEXT_END[];
extern char boot_TEXT_SIZE[];
extern char boot_TEXT_START[];
extern char boot_VRAM[];
extern char boot_VRAM_END[];
extern char boot_VRAM_SIZE[];
extern char boot_alloc_VRAM[];
extern char boot_alloc_VRAM_END[];
extern char boot_alloc_VRAM_SIZE[];
extern char boot_noload_VRAM[];
extern char boot_SBSS_START[];
extern char boot_SBSS_END[];
extern char boot_SBSS_SIZE[];
extern char boot_SCOMMON_START[];
extern char boot_SCOMMON_END[];
extern char boot_SCOMMON_SIZE[];
extern char boot_BSS_START[];
extern char boot_BSS_END[];
extern char boot_BSS_SIZE[];
extern char bootCOMMON_START[];
extern char bootCOMMON_END[];
extern char bootCOMMON_SIZE[];
extern char boot_noload_VRAM_END[];
extern char boot_noload_VRAM_SIZE[];
extern char kanjiCOMMON_END[];
extern char kanjiCOMMON_SIZE[];
extern char kanjiCOMMON_START[];
extern char kanji_BSS_END[];
extern char kanji_BSS_SIZE[];
extern char kanji_BSS_START[];
extern char boot_VRAM_END[];
extern char boot_VRAM_SIZE[];
extern char boot_ROM_END[];
extern char boot_ROM_SIZE[];
extern char kanji_ROM_START[];
extern char kanji_VRAM[];
extern char kanji_alloc_VRAM[];
extern char kanji_TEXT_START[];
extern char kanji_TEXT_END[];
extern char kanji_TEXT_SIZE[];
extern char kanji_DATA_START[];
extern char kanji_DATA_END[];
extern char kanji_DATA_SIZE[];
extern char kanji_DATA_START[];
extern char kanji_RODATA_START[];
extern char kanji_RODATA_END[];
extern char kanji_RODATA_SIZE[];
extern char kanji_RODATA_START[];
extern char kanji_ROM_END[];
extern char kanji_ROM_SIZE[];
extern char kanji_ROM_START[];
extern char kanji_SBSS_END[];
extern char kanji_SBSS_SIZE[];
extern char kanji_SBSS_START[];
extern char kanji_SCOMMON_END[];
extern char kanji_SCOMMON_SIZE[];
extern char kanji_SCOMMON_START[];
extern char kanji_SDATA_START[];
extern char kanji_SDATA_END[];
extern char kanji_SDATA_SIZE[];
extern char kanji_SDATA_START[];
extern char kanji_TEXT_END[];
extern char kanji_TEXT_SIZE[];
extern char kanji_TEXT_START[];
extern char kanji_VRAM[];
extern char kanji_VRAM_END[];
extern char kanji_VRAM_SIZE[];
extern char kanji_alloc_VRAM[];
extern char kanji_alloc_VRAM_END[];
extern char kanji_alloc_VRAM_SIZE[];
extern char kanji_noload_VRAM[];
extern char kanji_SBSS_START[];
extern char kanji_SBSS_END[];
extern char kanji_SBSS_SIZE[];
extern char kanji_SCOMMON_START[];
extern char kanji_SCOMMON_END[];
extern char kanji_SCOMMON_SIZE[];
extern char kanji_BSS_START[];
extern char kanji_BSS_END[];
extern char kanji_BSS_SIZE[];
extern char kanjiCOMMON_START[];
extern char kanjiCOMMON_END[];
extern char kanjiCOMMON_SIZE[];
extern char kanji_noload_VRAM_END[];
extern char kanji_noload_VRAM_SIZE[];
extern char mainCOMMON_END[];
extern char mainCOMMON_SIZE[];
extern char mainCOMMON_START[];
extern char main_BSS_END[];
extern char main_BSS_SIZE[];
extern char main_BSS_START[];
extern char kanji_VRAM_END[];
extern char kanji_VRAM_SIZE[];
extern char kanji_ROM_END[];
extern char kanji_ROM_SIZE[];
extern char main_ROM_START[];
extern char main_VRAM[];
extern char main_alloc_VRAM[];
extern char main_TEXT_START[];
extern char main_TEXT_END[];
extern char main_TEXT_SIZE[];
extern char main_DATA_START[];
extern char main_DATA_END[];
extern char main_DATA_SIZE[];
extern char main_DATA_START[];
extern char main_RODATA_START[];
extern char main_RODATA_END[];
extern char main_RODATA_SIZE[];
extern char main_RODATA_START[];
extern char main_ROM_END[];
extern char main_ROM_SIZE[];
extern char main_ROM_START[];
extern char main_SBSS_END[];
extern char main_SBSS_SIZE[];
extern char main_SBSS_START[];
extern char main_SCOMMON_END[];
extern char main_SCOMMON_SIZE[];
extern char main_SCOMMON_START[];
extern char main_SDATA_START[];
extern char main_SDATA_END[];
extern char main_SDATA_SIZE[];
extern char main_SDATA_START[];
extern char main_TEXT_END[];
extern char main_TEXT_SIZE[];
extern char main_TEXT_START[];
extern char main_VRAM[];
extern char main_VRAM_END[];
extern char main_VRAM_SIZE[];
extern char main_alloc_VRAM[];
extern char main_alloc_VRAM_END[];
extern char main_alloc_VRAM_SIZE[];
extern char main_noload_VRAM[];
extern char main_SBSS_START[];
extern char main_SBSS_END[];
extern char main_SBSS_SIZE[];
extern char main_SCOMMON_START[];
extern char main_SCOMMON_END[];
extern char main_SCOMMON_SIZE[];
extern char main_BSS_START[];
extern char main_BSS_END[];
extern char main_BSS_SIZE[];
extern char mainCOMMON_START[];
extern char mainCOMMON_END[];
extern char mainCOMMON_SIZE[];
extern char main_noload_VRAM_END[];
extern char main_noload_VRAM_SIZE[];
extern char main_VRAM_END[];
extern char main_VRAM_SIZE[];
extern char main_ROM_END[];
extern char main_ROM_SIZE[];

#endif
42 changes: 21 additions & 21 deletions tests/test_cases/hardcoded_gp.h
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
#ifndef HEADER_SYMBOLS_H
#define HEADER_SYMBOLS_H

extern Addr main_BSS_END;
extern Addr main_BSS_SIZE;
extern Addr main_BSS_START;
extern Addr main_DATA_END;
extern Addr main_DATA_SIZE;
extern Addr main_DATA_START;
extern Addr main_ROM_START;
extern Addr main_VRAM;
extern Addr main_alloc_VRAM;
extern Addr main_RODATA_START;
extern Addr main_RODATA_END;
extern Addr main_RODATA_SIZE;
extern Addr main_RODATA_START;
extern Addr main_ROM_END;
extern Addr main_ROM_SIZE;
extern Addr main_ROM_START;
extern Addr main_SBSS_END;
extern Addr main_SBSS_SIZE;
extern Addr main_SBSS_START;
extern Addr main_SDATA_END;
extern Addr main_SDATA_SIZE;
extern Addr main_SDATA_START;
extern Addr main_TEXT_START;
extern Addr main_TEXT_END;
extern Addr main_TEXT_SIZE;
extern Addr main_TEXT_START;
extern Addr main_VRAM;
extern Addr main_VRAM_END;
extern Addr main_VRAM_SIZE;
extern Addr main_alloc_VRAM;
extern Addr main_DATA_START;
extern Addr main_DATA_END;
extern Addr main_DATA_SIZE;
extern Addr main_SDATA_START;
extern Addr main_SDATA_END;
extern Addr main_SDATA_SIZE;
extern Addr main_SBSS_START;
extern Addr main_SBSS_END;
extern Addr main_SBSS_SIZE;
extern Addr main_BSS_START;
extern Addr main_BSS_END;
extern Addr main_BSS_SIZE;
extern Addr main_alloc_VRAM_END;
extern Addr main_alloc_VRAM_SIZE;
extern Addr main_noload_VRAM;
extern Addr main_noload_VRAM_END;
extern Addr main_noload_VRAM_SIZE;
extern Addr main_VRAM_END;
extern Addr main_VRAM_SIZE;
extern Addr main_ROM_END;
extern Addr main_ROM_SIZE;

#endif
Loading

0 comments on commit 8998c5a

Please sign in to comment.