Skip to content

Commit 4cea939

Browse files
authored
Merge pull request #20988 from Veykril/push-rutmxykksupu
Merge `smol_str` into rust-analyzer
2 parents ed2ae23 + 64b00e7 commit 4cea939

File tree

17 files changed

+2726
-26
lines changed

17 files changed

+2726
-26
lines changed

Cargo.lock

Lines changed: 498 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/smol_str/.github/ci.rs

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
use std::{
2+
env, fs,
3+
process::{self, Command, ExitStatus, Stdio},
4+
time::Instant,
5+
};
6+
7+
type Error = Box<dyn std::error::Error>;
8+
type Result<T> = std::result::Result<T, Error>;
9+
10+
fn main() {
11+
if let Err(err) = try_main() {
12+
eprintln!("{}", err);
13+
process::exit(1);
14+
}
15+
}
16+
17+
fn try_main() -> Result<()> {
18+
let cwd = env::current_dir()?;
19+
let cargo_toml = cwd.join("Cargo.toml");
20+
assert!(
21+
cargo_toml.exists(),
22+
"Cargo.toml not found, cwd: {}",
23+
cwd.display()
24+
);
25+
26+
{
27+
let _s = Section::new("BUILD_NO_DEFAULT_FEATURES");
28+
shell("cargo test --all-features --workspace --no-run --no-default-features")?;
29+
}
30+
31+
{
32+
let _s = Section::new("BUILD");
33+
shell("cargo test --all-features --workspace --no-run")?;
34+
}
35+
36+
{
37+
let _s = Section::new("TEST");
38+
shell("cargo test --all-features --workspace")?;
39+
shell("cargo test --no-default-features --workspace")?;
40+
}
41+
42+
{
43+
let _s = Section::new("TEST_BENCHES");
44+
shell("cargo test --benches --all-features")?;
45+
}
46+
47+
let current_branch = shell_output("git branch --show-current")?;
48+
if &current_branch == "master" {
49+
let _s = Section::new("PUBLISH");
50+
let manifest = fs::read_to_string(&cargo_toml)?;
51+
let version = get_field(&manifest, "version")?;
52+
let tag = format!("v{}", version);
53+
let tags = shell_output("git tag --list")?;
54+
55+
if !tags.contains(&tag) {
56+
let token = env::var("CRATES_IO_TOKEN").unwrap();
57+
shell(&format!("git tag v{}", version))?;
58+
shell(&format!("cargo publish --token {}", token))?;
59+
shell("git push --tags")?;
60+
}
61+
}
62+
Ok(())
63+
}
64+
65+
fn get_field<'a>(text: &'a str, name: &str) -> Result<&'a str> {
66+
for line in text.lines() {
67+
let words = line.split_ascii_whitespace().collect::<Vec<_>>();
68+
match words.as_slice() {
69+
[n, "=", v, ..] if n.trim() == name => {
70+
assert!(v.starts_with('"') && v.ends_with('"'));
71+
return Ok(&v[1..v.len() - 1]);
72+
}
73+
_ => (),
74+
}
75+
}
76+
Err(format!("can't find `{}` in\n----\n{}\n----\n", name, text))?
77+
}
78+
79+
fn shell(cmd: &str) -> Result<()> {
80+
let status = command(cmd).status()?;
81+
check_status(status)
82+
}
83+
84+
fn shell_output(cmd: &str) -> Result<String> {
85+
let output = command(cmd).stderr(Stdio::inherit()).output()?;
86+
check_status(output.status)?;
87+
let res = String::from_utf8(output.stdout)?;
88+
let res = res.trim().to_string();
89+
println!("{}", res);
90+
Ok(res)
91+
}
92+
93+
fn command(cmd: &str) -> Command {
94+
eprintln!("> {}", cmd);
95+
let words = cmd.split_ascii_whitespace().collect::<Vec<_>>();
96+
let (cmd, args) = words.split_first().unwrap();
97+
let mut res = Command::new(cmd);
98+
res.args(args);
99+
res
100+
}
101+
102+
fn check_status(status: ExitStatus) -> Result<()> {
103+
if !status.success() {
104+
Err(format!("$status: {}", status))?;
105+
}
106+
Ok(())
107+
}
108+
109+
struct Section {
110+
name: &'static str,
111+
start: Instant,
112+
}
113+
114+
impl Section {
115+
fn new(name: &'static str) -> Section {
116+
println!("::group::{}", name);
117+
let start = Instant::now();
118+
Section { name, start }
119+
}
120+
}
121+
122+
impl Drop for Section {
123+
fn drop(&mut self) {
124+
eprintln!("{}: {:.2?}", self.name, self.start.elapsed());
125+
println!("::endgroup::");
126+
}
127+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: CI
2+
on:
3+
pull_request:
4+
push:
5+
branches:
6+
- master
7+
- staging
8+
- trying
9+
10+
env:
11+
CARGO_INCREMENTAL: 0
12+
CARGO_NET_RETRY: 10
13+
CI: 1
14+
RUST_BACKTRACE: short
15+
RUSTFLAGS: -D warnings
16+
RUSTUP_MAX_RETRIES: 10
17+
18+
jobs:
19+
rust:
20+
name: Rust
21+
runs-on: ubuntu-latest
22+
23+
steps:
24+
- name: Checkout repository
25+
uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0
28+
29+
- name: Install Rust toolchain
30+
uses: actions-rust-lang/setup-rust-toolchain@v1
31+
with:
32+
cache: false
33+
34+
- run: rustc ./.github/ci.rs && ./ci
35+
env:
36+
CRATES_IO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}

lib/smol_str/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/target
2+
/ci
3+
/.vscode
4+
Cargo.lock

lib/smol_str/CHANGELOG.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
## 0.3.4 - 2025-10-23
6+
7+
- Added `rust-version` field to `Cargo.toml`
8+
9+
## 0.3.3 - 2025-10-23
10+
11+
- Optimise `StrExt::to_ascii_lowercase_smolstr`, `StrExt::to_ascii_uppercase_smolstr`
12+
~2x speedup inline, ~4-22x for heap.
13+
- Optimise `StrExt::to_lowercase_smolstr`, `StrExt::to_uppercase_smolstr` ~2x speedup inline, ~5-50x for heap.
14+
- Optimise `StrExt::replace_smolstr`, `StrExt::replacen_smolstr` for single ascii replace,
15+
~3x speedup inline & heap.
16+
17+
## 0.3.2 - 2024-10-23
18+
19+
- Fix `SmolStrBuilder::push` incorrectly padding null bytes when spilling onto the heap on a
20+
multibyte character push
21+
22+
## 0.3.1 - 2024-09-04
23+
24+
- Fix `SmolStrBuilder` leaking implementation details
25+
26+
## 0.3.0 - 2024-09-04
27+
28+
- Remove deprecated `SmolStr::new_inline_from_ascii` function
29+
- Remove `SmolStr::to_string` in favor of `ToString::to_string`
30+
- Add `impl AsRef<[u8]> for SmolStr` impl
31+
- Add `impl AsRef<OsStr> for SmolStr` impl
32+
- Add `impl AsRef<Path> for SmolStr` impl
33+
- Add `SmolStrBuilder`
34+
35+
## 0.2.2 - 2024-05-14
36+
37+
- Add `StrExt` trait providing `to_lowercase_smolstr`, `replace_smolstr` and similar
38+
- Add `PartialEq` optimization for `ptr_eq`-able representations

lib/smol_str/Cargo.toml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[package]
2+
name = "smol_str"
3+
version = "0.3.4"
4+
description = "small-string optimized string type with O(1) clone"
5+
license = "MIT OR Apache-2.0"
6+
repository = "https://github.com/rust-lang/rust-analyzer/tree/master/lib/smol_str"
7+
authors = ["Aleksey Kladov <aleksey.kladov@gmail.com>", "Lukas Wirth <lukastw97@gmail.com>"]
8+
edition = "2021"
9+
rust-version = "1.89"
10+
11+
[package.metadata.docs.rs]
12+
rustdoc-args = ["--cfg", "docsrs"]
13+
all-features = true
14+
15+
[dependencies]
16+
serde_core = { version = "1.0.220", optional = true, default-features = false }
17+
borsh = { version = "1.4.0", optional = true, default-features = false }
18+
arbitrary = { version = "1.3", optional = true }
19+
20+
[dev-dependencies]
21+
proptest = "1.5"
22+
serde_json = "1.0"
23+
serde = { version = "1.0", features = ["derive"] }
24+
criterion = "0.7"
25+
rand = "0.9.2"
26+
27+
[features]
28+
default = ["std"]
29+
std = ["serde_core?/std", "borsh?/std"]
30+
serde = ["dep:serde_core"]
31+
32+
[[bench]]
33+
name = "bench"
34+
harness = false
35+
36+
[lints]
37+
workspace = true

0 commit comments

Comments
 (0)