Refactor path string replacements with append_path()
- Dominant language
- Rust
- Stars
- 7
- Forks
- 11
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 5
Description
In a separate PR, but this is especially egregious. This is a more expensive way - and results in more (re)allocations - than just building the URL the way .NET does. We could easily see in TypeScript that each segment is just a variable, and then build up the path. `String` will grow as needed. Replacing like this forces it to regrow at a potentially slower pace, and means going through the string O(n) every single time.
_Originally posted by @heaths in https://github.com/Azure/typespec-rust/pull/635#discussion_r2450010422_
I.e. instead of
```rust
let mut path_var = String::from("/colliding/{request}/{coreReq}/{path}/{url}");
path_var = path_var.replace("{coreReq}", core_req);
path_var = path_var.replace("{path}", path);
path_var = path_var.replace("{request}", request);
path_var = path_var.replace("{url}", url);
```
Do
```rust
url.append_path("colliding")
url.append_path(request);
url.append_path(core_req);
url.append_path(path);
url.append_path(url);
```
Contributor guide
Assessment
This issue has not been assessed yet.