Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7fcb7869
Kaydet (Commit)
7fcb7869
authored
Şub 07, 2005
tarafından
Raymond Hettinger
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adopt Skip's idea to optimize lists of constants in the context
of a "in" or "not in" test.
üst
fe59dc1b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
8 deletions
+15
-8
test_peepholer.py
Lib/test/test_peepholer.py
+2
-1
compile.c
Python/compile.c
+13
-7
No files found.
Lib/test/test_peepholer.py
Dosyayı görüntüle @
7fcb7869
...
@@ -135,7 +135,8 @@ class TestTranforms(unittest.TestCase):
...
@@ -135,7 +135,8 @@ class TestTranforms(unittest.TestCase):
def
test_set_conversion
(
self
):
def
test_set_conversion
(
self
):
for
line
in
(
for
line
in
(
'x in (1,2,3)'
,
'x in [1,2,3]'
,
'x in (1,2,3)'
,
'x not in (1,2,3)'
,
'x not in (1,2,3)'
,
'not x in (1,2,3)'
,
'not x in (1,2,3)'
,
'not x not in (1,2,3)'
,
'not x not in (1,2,3)'
,
...
...
Python/compile.c
Dosyayı görüntüle @
7fcb7869
...
@@ -397,7 +397,9 @@ intern_strings(PyObject *tuple)
...
@@ -397,7 +397,9 @@ intern_strings(PyObject *tuple)
The consts table must still be in list form so that the
The consts table must still be in list form so that the
new constant (c1, c2, ... cn) can be appended.
new constant (c1, c2, ... cn) can be appended.
Called with codestr pointing to the first LOAD_CONST.
Called with codestr pointing to the first LOAD_CONST.
Bails out with no change if one or more of the LOAD_CONSTs is missing. */
Bails out with no change if one or more of the LOAD_CONSTs is missing.
Also works for BUILD_LIST when followed by an "in" or "not in" test.
*/
static
int
static
int
tuple_of_constants
(
unsigned
char
*
codestr
,
int
n
,
PyObject
*
consts
)
tuple_of_constants
(
unsigned
char
*
codestr
,
int
n
,
PyObject
*
consts
)
{
{
...
@@ -406,7 +408,7 @@ tuple_of_constants(unsigned char *codestr, int n, PyObject *consts)
...
@@ -406,7 +408,7 @@ tuple_of_constants(unsigned char *codestr, int n, PyObject *consts)
/* Pre-conditions */
/* Pre-conditions */
assert
(
PyList_CheckExact
(
consts
));
assert
(
PyList_CheckExact
(
consts
));
assert
(
codestr
[
n
*
3
]
==
BUILD_TUPLE
);
assert
(
codestr
[
n
*
3
]
==
BUILD_TUPLE
||
codestr
[
n
*
3
]
==
BUILD_LIST
);
assert
(
GETARG
(
codestr
,
(
n
*
3
))
==
n
);
assert
(
GETARG
(
codestr
,
(
n
*
3
))
==
n
);
for
(
i
=
0
;
i
<
n
;
i
++
)
for
(
i
=
0
;
i
<
n
;
i
++
)
assert
(
codestr
[
i
*
3
]
==
LOAD_CONST
);
assert
(
codestr
[
i
*
3
]
==
LOAD_CONST
);
...
@@ -753,24 +755,28 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
...
@@ -753,24 +755,28 @@ optimize_code(PyObject *code, PyObject* consts, PyObject *names, PyObject *linen
cumlc
=
0
;
cumlc
=
0
;
break
;
break
;
/* Try to fold tuples of constants.
/* Try to fold tuples of constants (includes a case for lists
which are only used for "in" and "not in" tests).
Skip over BUILD_SEQN 1 UNPACK_SEQN 1.
Skip over BUILD_SEQN 1 UNPACK_SEQN 1.
Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2.
Replace BUILD_SEQN 2 UNPACK_SEQN 2 with ROT2.
Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */
Replace BUILD_SEQN 3 UNPACK_SEQN 3 with ROT3 ROT2. */
case
BUILD_TUPLE
:
case
BUILD_TUPLE
:
case
BUILD_LIST
:
j
=
GETARG
(
codestr
,
i
);
j
=
GETARG
(
codestr
,
i
);
h
=
i
-
3
*
j
;
h
=
i
-
3
*
j
;
if
(
h
>=
0
&&
if
(
h
>=
0
&&
j
<=
lastlc
&&
j
<=
lastlc
&&
ISBASICBLOCK
(
blocks
,
h
,
3
*
(
j
+
1
))
&&
(
opcode
==
BUILD_TUPLE
&&
ISBASICBLOCK
(
blocks
,
h
,
3
*
(
j
+
1
))
||
opcode
==
BUILD_LIST
&&
codestr
[
i
+
3
]
==
COMPARE_OP
&&
ISBASICBLOCK
(
blocks
,
h
,
3
*
(
j
+
2
))
&&
(
GETARG
(
codestr
,
i
+
3
)
==
6
||
GETARG
(
codestr
,
i
+
3
)
==
7
))
&&
tuple_of_constants
(
&
codestr
[
h
],
j
,
consts
))
{
tuple_of_constants
(
&
codestr
[
h
],
j
,
consts
))
{
assert
(
codestr
[
i
]
==
LOAD_CONST
);
assert
(
codestr
[
i
]
==
LOAD_CONST
);
cumlc
=
1
;
cumlc
=
1
;
break
;
break
;
}
}
/* Intentional fallthrough */
case
BUILD_LIST
:
j
=
GETARG
(
codestr
,
i
);
if
(
codestr
[
i
+
3
]
!=
UNPACK_SEQUENCE
||
if
(
codestr
[
i
+
3
]
!=
UNPACK_SEQUENCE
||
!
ISBASICBLOCK
(
blocks
,
i
,
6
)
||
!
ISBASICBLOCK
(
blocks
,
i
,
6
)
||
j
!=
GETARG
(
codestr
,
i
+
3
))
j
!=
GETARG
(
codestr
,
i
+
3
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment