Open
Description
Issue
The last line of the Page
class reads:
self.pages = int(math.ceil(total / float(page_size)))
This is heavy because it is importing the entire math
and because it's getting into the woods with cross conversions into float
and back to int
. Furthermore, math
is being imported just for the sake of ceil
.
First fix
As a first approach, I'd have gone with:
from math import ceil
...
self.pages = int(ceil(total / float(page_size)))
but this is just a small optimisation on the exact same solution, thinking of those of us that deal with embedded devices and fight for space.
Second fix
I'd like to put it to you that there is a simpler, lighter way to accomplish this:
self.pages = (total // page_size) + 1
This fix is:
- universal, in the sense that neither
total
norpage_size
are allowed to be negative or zero; - lighter, as it keeps calculations to a minimum and within language constructs.
I hope this helps.
Metadata
Metadata
Assignees
Labels
No labels