Skip to content

Commit 5082a22

Browse files
authored
[mypyc] Document optimized bytes ops and additional str ops (#18242)
The docs were somewhat out of date.
1 parent ee19ea7 commit 5082a22

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

mypyc/doc/bytes_operations.rst

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.. _bytes-ops:
2+
3+
Native bytes operations
4+
========================
5+
6+
These ``bytes`` operations have fast, optimized implementations. Other
7+
bytes operations use generic implementations that are often slower.
8+
9+
Construction
10+
------------
11+
12+
* Bytes literal
13+
* ``bytes(x: list)``
14+
15+
Operators
16+
---------
17+
18+
* Concatenation (``b1 + b2``)
19+
* Indexing (``b[n]``)
20+
* Slicing (``b[n:m]``, ``b[n:]``, ``b[:m]``)
21+
* Comparisons (``==``, ``!=``)
22+
23+
.. _bytes-methods:
24+
25+
Methods
26+
-------
27+
28+
* ``b.decode()``
29+
* ``b.decode(encoding: str)``
30+
* ``b.decode(encoding: str, errors: str)``
31+
* ``b.join(x: Iterable)``
32+
33+
.. note::
34+
35+
:ref:`str.encode() <str-methods>` is also optimized.
36+
37+
Formatting
38+
----------
39+
40+
A subset of % formatting operations are optimized (``b"..." % (...)``).
41+
42+
Functions
43+
---------
44+
45+
* ``len(b: bytes)``
46+
* ``ord(b: bytes)``

mypyc/doc/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ generate fast code.
3636
bool_operations
3737
float_operations
3838
str_operations
39+
bytes_operations
3940
list_operations
4041
dict_operations
4142
set_operations

mypyc/doc/str_operations.rst

+20-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ Operators
2222
* Comparisons (``==``, ``!=``)
2323
* Augmented assignment (``s1 += s2``)
2424

25+
.. _str-methods:
26+
2527
Methods
2628
-------
2729

30+
* ``s.encode()``
31+
* ``s.encode(encoding: str)``
32+
* ``s.encode(encoding: str, errors: str)``
2833
* ``s1.endswith(s2: str)``
2934
* ``s.join(x: Iterable)``
3035
* ``s.replace(old: str, new: str)``
@@ -34,8 +39,21 @@ Methods
3439
* ``s.split(sep: str, maxsplit: int)``
3540
* ``s1.startswith(s2: str)``
3641

42+
.. note::
43+
44+
:ref:`bytes.decode() <bytes-methods>` is also optimized.
45+
46+
Formatting
47+
----------
48+
49+
A subset of these common string formatting expressions are optimized:
50+
51+
* F-strings
52+
* ``"...".format(...)``
53+
* ``"..." % (...)``
54+
3755
Functions
3856
---------
3957

40-
* ``len(s: str)``
41-
* ``ord(s: str)``
58+
* ``len(s: str)``
59+
* ``ord(s: str)``

0 commit comments

Comments
 (0)