mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-04-15 04:08:47 +00:00
Fix obvious Python performance suboptimality
This commit is contained in:
parent
5a441ea57f
commit
b703eee96e
1 changed files with 7 additions and 9 deletions
16
third_party/python/Parser/node.c
vendored
16
third_party/python/Parser/node.c
vendored
|
@ -1,7 +1,9 @@
|
|||
/* Parse tree node implementation */
|
||||
/* clang-format off */
|
||||
|
||||
#include "Python.h"
|
||||
#include "node.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "errcode.h"
|
||||
|
||||
node *
|
||||
|
@ -20,17 +22,13 @@ PyNode_New(int type)
|
|||
|
||||
/* See comments at XXXROUNDUP below. Returns -1 on overflow. */
|
||||
static int
|
||||
fancy_roundup(int n)
|
||||
fancy_roundup(int x)
|
||||
{
|
||||
/* Round up to the closest power of 2 >= n. */
|
||||
int result = 256;
|
||||
assert(n > 128);
|
||||
while (result < n) {
|
||||
result <<= 1;
|
||||
if (result <= 0)
|
||||
return -1;
|
||||
}
|
||||
return result;
|
||||
int r;
|
||||
assert(x > 128);
|
||||
r = 1u << (bsr(x - 1) + 1); /* hacker's delight */
|
||||
return r > 0 ? r : -1;
|
||||
}
|
||||
|
||||
/* A gimmick to make massive numbers of reallocs quicker. The result is
|
||||
|
|
Loading…
Add table
Reference in a new issue