dead_code.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:fatoptimizer 作者: vstinner 项目源码 文件源码
def remove_dead_code(optimizer, node_list):
    """Remove dead code.

    Modify node_list in-place.
    Example: replace "return 1; return 2" with "return 1".
    """

    truncate = None
    stop = len(node_list) - 1
    for index, node in enumerate(node_list):
        if index == stop:
            break
        if not isinstance(node, (ast.Return, ast.Raise)):
            continue
        if not can_remove(node_list[index+1:]):
            continue
        truncate = index
        break
    # FIXME: use for/else: ?
    if truncate is None:
        return node_list
    optimizer.log_node_removal("Remove unreachable code", node_list[truncate+1:])
    return node_list[:truncate+1]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号