1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: rxvtutil.C |
2 | * File: rxvtutil.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2004-2006 Marc Lehmann <pcg@goof.com> |
… | |
… | |
44 | |
44 | |
45 | e = w.u; |
45 | e = w.u; |
46 | } |
46 | } |
47 | |
47 | |
48 | #if !HAVE_GCC_BUILTINS |
48 | #if !HAVE_GCC_BUILTINS |
49 | int ctz (unsigned int x) CONST |
49 | int rxvt_ctz (unsigned int x) CONST |
50 | { |
50 | { |
51 | int r = 0; |
51 | int r = 0; |
52 | |
52 | |
53 | x &= -x; // this isolates the lowest bit |
53 | x &= -x; // this isolates the lowest bit |
54 | |
54 | |
… | |
… | |
59 | if (x & 0xffff0000) r += 16; |
59 | if (x & 0xffff0000) r += 16; |
60 | |
60 | |
61 | return r; |
61 | return r; |
62 | } |
62 | } |
63 | |
63 | |
64 | int popcount (unsigned int x) CONST |
64 | int rxvt_popcount (unsigned int x) CONST |
65 | { |
65 | { |
66 | x -= (x >> 1) & 0x55555555; |
66 | x -= (x >> 1) & 0x55555555; |
67 | x = ((x >> 2) & 0x33333333) + (x & 0x33333333); |
67 | x = ((x >> 2) & 0x33333333) + (x & 0x33333333); |
68 | x = ((x >> 4) + x) & 0x0f0f0f0f; |
68 | x = ((x >> 4) + x) & 0x0f0f0f0f; |
69 | x *= 0x01010101; |
69 | x *= 0x01010101; |
… | |
… | |
92 | |
92 | |
93 | void * |
93 | void * |
94 | rxvt_temp_buf (int len) |
94 | rxvt_temp_buf (int len) |
95 | { |
95 | { |
96 | if (len > temp_len) |
96 | if (len > temp_len) |
97 | { |
97 | { |
98 | free (temp_buf); |
|
|
99 | temp_buf = malloc (len); |
98 | temp_buf = realloc (temp_buf, len); |
100 | temp_len = len; |
99 | temp_len = len; |
101 | } |
100 | } |
102 | |
101 | |
103 | return temp_buf; |
102 | return temp_buf; |
104 | } |
103 | } |
105 | |
104 | |
106 | |
105 | |