Skip to content

Commit 85c17f6

Browse files
committed
perf: Use ToString trait during error handling to avoid using a formatter
1 parent 6732346 commit 85c17f6

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

python/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111

1212
- Switch from `openssl` to `rustls` in `attohttpc` dependency. [#49](https://github.com/Stranger6667/css-inline/issues/49)
1313

14+
15+
### Performance
16+
17+
- Use `ToString` trait during error handling to avoid using a formatter.
18+
1419
## [0.3.2] - 2020-07-09
1520

1621
### Fixed

python/benches/bench.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import multiprocessing
2+
from contextlib import suppress
23

34
import inlinestyler.utils
45
import premailer
@@ -204,3 +205,12 @@ def test_realistic(benchmark, func):
204205
@pytest.mark.benchmark(group="realistic many")
205206
def test_realistic_many(benchmark, func):
206207
benchmark(func, REALISTIC_HTMLS)
208+
209+
210+
@pytest.mark.benchmark(group="exception")
211+
def test_exception(benchmark):
212+
def func():
213+
with suppress(ValueError):
214+
css_inline.inline("", base_url="!wrong!")
215+
216+
benchmark(func)

python/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ struct InlineErrorWrapper(rust_inline::InlineError);
1313
impl From<InlineErrorWrapper> for PyErr {
1414
fn from(error: InlineErrorWrapper) -> Self {
1515
match error.0 {
16-
rust_inline::InlineError::IO(error) => InlineError::py_err(format!("{}", error)),
17-
rust_inline::InlineError::Network(error) => InlineError::py_err(format!("{}", error)),
16+
rust_inline::InlineError::IO(error) => InlineError::py_err(error.to_string()),
17+
rust_inline::InlineError::Network(error) => InlineError::py_err(error.to_string()),
1818
rust_inline::InlineError::ParseError(message) => InlineError::py_err(message),
1919
}
2020
}
@@ -24,7 +24,7 @@ struct UrlError(url::ParseError);
2424

2525
impl From<UrlError> for PyErr {
2626
fn from(error: UrlError) -> Self {
27-
exceptions::ValueError::py_err(format!("{}", error.0))
27+
exceptions::ValueError::py_err(error.0.to_string())
2828
}
2929
}
3030

0 commit comments

Comments
 (0)