Skip to content

Commit 44cc6cd

Browse files
committed
[mypyc] Document optimized bytes ops and additional str ops
1 parent ee19ea7 commit 44cc6cd

File tree

3 files changed

+55
-2
lines changed

3 files changed

+55
-2
lines changed

mypyc/doc/bytes_operations.rst

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
Methods
24+
-------
25+
26+
* ``b.decode()``
27+
* ``b.decode(encoding: str)``
28+
* ``b.decode(encoding: str, errors: str)``
29+
* ``b.join(x: Iterable)``
30+
31+
Formatting
32+
----------
33+
34+
A subset of % formatting operations are optimized (``b"..." % (...)``).
35+
36+
Functions
37+
---------
38+
39+
* ``len(b: bytes)``
40+
* ``ord(b: bytes)``

mypyc/doc/index.rst

Lines changed: 1 addition & 0 deletions
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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ Operators
2525
Methods
2626
-------
2727

28+
* ``s.encode()``
29+
* ``s.encode(encoding: str)``
30+
* ``s.encode(encoding: str, errors: str)``
2831
* ``s1.endswith(s2: str)``
2932
* ``s.join(x: Iterable)``
3033
* ``s.replace(old: str, new: str)``
@@ -34,8 +37,17 @@ Methods
3437
* ``s.split(sep: str, maxsplit: int)``
3538
* ``s1.startswith(s2: str)``
3639

40+
Formatting
41+
----------
42+
43+
A subset of these common string formatting expressions are optimized:
44+
45+
* F-strings
46+
* ``"...".format(...)``
47+
* ``"..." % (...)``
48+
3749
Functions
3850
---------
3951

40-
* ``len(s: str)``
41-
* ``ord(s: str)``
52+
* ``len(s: str)``
53+
* ``ord(s: str)``

0 commit comments

Comments
 (0)