cython/cython

Cache constant frozen-sets

クローズ

#2,741 opened on 2018/11/30

 (7 件のコメント) (0 件のリアクション) (0 人の担当者)Python (1,517 件のフォーク)batch import
Code GenerationOptimizationgood first issue

Repository metrics

Stars
 (8,663 個のスター)
PR merge metrics
 (平均マージ 45d 12h) (30d で 52 merged PRs)

説明

Some set constants can be replaced by frozensets, e.g. in cases like x in {1,2,3}. This would allow them to become global constants, created once at module init time. There is already a framework for merging tuple and string constants, see TupleNode. The ConstantFolding transformation could detect these cases and set a flag attribute on the SetNode instances that would trigger constant frozenset behaviour.

Other potential candidates:

>>> frozenset((1,2,3)) | {2,3,4}  # imagine one side being non-constant
frozenset([1, 2, 3, 4])
>>> {3,4,5} | frozenset((1,2,3))
set([1, 2, 3, 4, 5])

コントリビューターガイド