diff --git a/CHANGELOG.md b/CHANGELOG.md index 949a196..54a830e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,8 @@ Types of changes - A `--threads` flag, so you can pick how many formatting threads to spawn. Defaults to the number of logical CPUs in your system. +- Position counters were improved to offer an extra 1.13x speedup. + ## [0.6.0] - 2022-02-25 ### Added diff --git a/README.md b/README.md index ac3897d..d15799f 100644 --- a/README.md +++ b/README.md @@ -203,15 +203,22 @@ Please see: [CHANGELOG.md](./CHANGELOG.md). - BogoMips: 7599.80 - Cache Size: 16384 KB + Using: + + ```bash + # x86_64-unknown-linux-gnu + $ time alejandra --threads $threads /path/to/nixpkgs + ``` + Results: - | Logical Cores | Seconds | - | :-----------: | :-----: | - | 1 | 15.1 | - | 2 | 7.9 | - | 4 | 5.4 | - | 8 | 4.1 | - | 16 | 3.6 | + | $threads | Seconds | + | :------: | :-----: | + | 1 | 13.4 | + | 2 | 6.9 | + | 4 | 3.6 | + | 8 | 2.6 | + | 16 | 3.1 | [^semantic-changes]: The methodology to claim this is: diff --git a/src/alejandra_engine/src/position.rs b/src/alejandra_engine/src/position.rs index d760b58..df0e23c 100644 --- a/src/alejandra_engine/src/position.rs +++ b/src/alejandra_engine/src/position.rs @@ -12,15 +12,13 @@ impl Default for Position { impl Position { pub fn update(&mut self, text: &str) { - let chars: Vec = text.chars().collect(); - let newlines = chars.iter().filter(|&c| *c == '\n').count(); - self.line += newlines; - if newlines > 0 { - self.column = 0 + for char in text.chars() { + if char == '\n' { + self.line += 1; + self.column = 0; + } else { + self.column += 1; + } } - self.column += match chars.iter().rposition(|c| *c == '\n') { - Some(pos) => chars.len() - pos - 1, - None => chars.len(), - }; } }