MCPcopy Index your code
hub / github.com/python/mypy / faster_min_max

Function faster_min_max

mypyc/irbuild/specialize.py:470–493  ·  view source on GitHub ↗
(builder: IRBuilder, expr: CallExpr, callee: RefExpr)

Source from the content-addressed store, hash-verified

468@specialize_function("builtins.min")
469@specialize_function("builtins.max")
470def faster_min_max(builder: IRBuilder, expr: CallExpr, callee: RefExpr) -> Value | None:
471 if expr.arg_kinds == [ARG_POS, ARG_POS]:
472 x, y = builder.accept(expr.args[0]), builder.accept(expr.args[1])
473 result = Register(builder.node_type(expr))
474 # CPython evaluates arguments reversely when calling min(...) or max(...)
475 if callee.fullname == "builtins.min":
476 comparison = builder.binary_op(y, x, "<", expr.line)
477 else:
478 comparison = builder.binary_op(y, x, ">", expr.line)
479
480 true_block, false_block, next_block = BasicBlock(), BasicBlock(), BasicBlock()
481 builder.add_bool_branch(comparison, true_block, false_block)
482
483 builder.activate_block(true_block)
484 builder.assign(result, builder.coerce(y, result.type, expr.line), expr.line)
485 builder.goto(next_block)
486
487 builder.activate_block(false_block)
488 builder.assign(result, builder.coerce(x, result.type, expr.line), expr.line)
489 builder.goto(next_block)
490
491 builder.activate_block(next_block)
492 return result
493 return None
494
495
496@specialize_function("builtins.tuple")

Callers

nothing calls this directly

Calls 10

RegisterClass · 0.90
BasicBlockClass · 0.90
node_typeMethod · 0.80
acceptMethod · 0.45
binary_opMethod · 0.45
add_bool_branchMethod · 0.45
activate_blockMethod · 0.45
assignMethod · 0.45
coerceMethod · 0.45
gotoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…