[Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Manciu, Catalin Gabriel
Hi everyone, While looking over the PyLong source code in Objects/longobject.c I came across the fact that the PyLong object doesnt't include implementation for basic inplace operations such as adding or multiplication: [...] long_long, /*nb_int*/ 0,

Re: [Python-Dev] Inplace operations for PyLong objects

2017-08-31 Thread Manciu, Catalin Gabriel
>On my machine, the more realistic code, with an implicit C loop, >the_value = sum(the_increment for i in range(total_iters)) >gives the same value twice as fast as your explicit Python loop. >(I cut total_iters down to 10**7). Your code is faster due to a number of reasons: - range in Python

Re: [Python-Dev] Inplace operations for PyLong objects

2017-09-01 Thread Manciu, Catalin Gabriel
> My question is -- how can the interpreter know if it can alter what is > supposed to be an immutable in-place? If it's used only internally to a > function, the it would be safe, but how to know that? > -CHB You can just check the reference count of your object, it's a member of the PyObject