Skip to content

Commit 4420344

Browse files
committed
perf(tsort): switch to the Bucket interning Backend for better lookup performance
1 parent 1e20789 commit 4420344

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/uu/tsort/src/tsort.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use std::ffi::OsString;
1111
use std::fs::File;
1212
use std::io::{self, BufRead, BufReader};
1313
use string_interner::StringInterner;
14-
use string_interner::backend::StringBackend;
14+
use string_interner::backend::BucketBackend;
1515
use thiserror::Error;
1616
use uucore::display::Quotable;
1717
use uucore::error::{UError, UResult, USimpleError};
1818
use uucore::{format_usage, show, translate};
1919

2020
// short types for switching interning behavior on the fly.
21-
type Sym = string_interner::symbol::SymbolU32;
22-
type Interner = StringInterner<StringBackend<Sym>>;
21+
type Sym = string_interner::symbol::SymbolUsize;
22+
type Interner = StringInterner<BucketBackend<Sym>>;
2323

2424
mod options {
2525
pub const FILE: &str = "file";
@@ -59,6 +59,8 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
5959
if input == "-" {
6060
process_input(io::stdin().lock(), &mut g)?;
6161
} else {
62+
// Windows reports a permission denied error when trying to read a directory.
63+
// So we check manually beforehand. On other systems, we avoid this extra check for performance.
6264
#[cfg(windows)]
6365
{
6466
use std::path::Path;
@@ -88,9 +90,9 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
8890
use std::os::unix::io::AsFd;
8991

9092
posix_fadvise(
91-
file.as_fd(), // file descriptor
92-
0, // start of the file
93-
0, // length 0 = all
93+
file.as_fd(),
94+
0, // offset 0 => from the start of the file
95+
0, // length 0 => for the whole file
9496
PosixFadviseAdvice::POSIX_FADV_SEQUENTIAL,
9597
)
9698
.ok();

0 commit comments

Comments
 (0)