New submission from Serhiy Storchaka:

The expression for testing that some index is in half-open range from 0 to 
limit can be written as

    index >= 0 && index < limit

or as

    (size_t)index < (size_t)limit

The latter form generates simpler machine code. This is idiomatic code, it is 
used in many C and C++ libraries (including C++ stdlib implementations). It 
already is used in CPython (in deque implementation).

Proposed patch rewrites index range checks in more efficient way. The patch was 
generated automatically by coccinelle script, and then manually cleaned up.

----------
components: Extension Modules, Interpreter Core
files: check_index.patch
keywords: patch
messages: 278355
nosy: serhiy.storchaka
priority: normal
severity: normal
stage: patch review
status: open
title: Faster index range checks
type: performance
versions: Python 3.7
Added file: http://bugs.python.org/file45034/check_index.patch

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28397>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to