mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-04-17 20:34:40 +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 */
|
/* Parse tree node implementation */
|
||||||
|
/* clang-format off */
|
||||||
|
|
||||||
#include "Python.h"
|
#include "Python.h"
|
||||||
#include "node.h"
|
#include "node.h"
|
||||||
|
#include "libc/nexgen32e/bsr.h"
|
||||||
#include "errcode.h"
|
#include "errcode.h"
|
||||||
|
|
||||||
node *
|
node *
|
||||||
|
@ -20,17 +22,13 @@ PyNode_New(int type)
|
||||||
|
|
||||||
/* See comments at XXXROUNDUP below. Returns -1 on overflow. */
|
/* See comments at XXXROUNDUP below. Returns -1 on overflow. */
|
||||||
static int
|
static int
|
||||||
fancy_roundup(int n)
|
fancy_roundup(int x)
|
||||||
{
|
{
|
||||||
/* Round up to the closest power of 2 >= n. */
|
/* Round up to the closest power of 2 >= n. */
|
||||||
int result = 256;
|
int r;
|
||||||
assert(n > 128);
|
assert(x > 128);
|
||||||
while (result < n) {
|
r = 1u << (bsr(x - 1) + 1); /* hacker's delight */
|
||||||
result <<= 1;
|
return r > 0 ? r : -1;
|
||||||
if (result <= 0)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* A gimmick to make massive numbers of reallocs quicker. The result is
|
/* A gimmick to make massive numbers of reallocs quicker. The result is
|
||||||
|
|
Loading…
Add table
Reference in a new issue