Skip to content

Commit 9daca87

Browse files
committed
x1.125 speed up
1 parent 7152d0b commit 9daca87

File tree

4 files changed

+4
-21
lines changed

4 files changed

+4
-21
lines changed

tests/test_url.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ def test_safe_url_performance(url):
639639
# presummably due to caching by urllib.
640640
number = 1 # TODO: Increase? How much?
641641
# Make sure the new implementation is at most this number of times as slow.
642-
multiplier = 45 # TODO: Lower as close to 1 as possible.
642+
multiplier = 40 # TODO: Lower as close to 1 as possible.
643643

644644
time1 = timeit(
645645
f"safe_url({url!r})", "from w3lib.url import safe_url", number=number

w3lib/_rfc5892.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111

1212
def _check_contextj_rules(label: str) -> None:
13+
if label.isascii():
14+
return
1315
for i, code_point in enumerate(label):
1416
value = ord(code_point)
1517
if not intranges_contain(value, codepoint_classes["CONTEXTJ"]):

w3lib/_url.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -432,25 +432,6 @@ def _starts_with_windows_drive_letter(input: str) -> bool:
432432
)
433433

434434

435-
_ASCII_URL_CODE_POINTS = _ASCII_ALPHANUMERIC + "!$&'()*+,-./:;=?@_~"
436-
437-
438-
# https://url.spec.whatwg.org/commit-snapshots/a46cb9188a48c2c9d80ba32a9b1891652d6b4900/#url-code-points
439-
def _is_url_code_point(code_point: str) -> bool:
440-
if code_point in _ASCII_URL_CODE_POINTS:
441-
return True
442-
code_point_id = ord(code_point)
443-
if code_point_id < 0xA0:
444-
return False
445-
if code_point_id > 0x10FFFD:
446-
return False
447-
if _is_surrogate_code_point_id(code_point_id):
448-
return False
449-
if _is_noncharacter_code_point_id(code_point_id):
450-
return False
451-
return True
452-
453-
454435
# https://url.spec.whatwg.org/commit-snapshots/a46cb9188a48c2c9d80ba32a9b1891652d6b4900/#double-dot-path-segment
455436
def _is_double_dot_path_segment(input: str) -> bool:
456437
return input in (

w3lib/_utr46.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ def _process(
256256

257257

258258
def _convert_label(label: str) -> str:
259-
if not any(ord(code_point) >= 0x80 for code_point in label):
259+
if label.isascii():
260260
return label
261261
return f"xn--{label.encode('punycode').decode()}"
262262

0 commit comments

Comments
 (0)