##// END OF EJS Templates
util: add clang-format control comment around struct and format macro...
Augie Fackler -
r34636:3455e2e2 default
parent child Browse files
Show More
@@ -1,50 +1,52
1 1 /*
2 2 util.h - utility functions for interfacing with the various python APIs.
3 3
4 4 This software may be used and distributed according to the terms of
5 5 the GNU General Public License, incorporated herein by reference.
6 6 */
7 7
8 8 #ifndef _HG_UTIL_H_
9 9 #define _HG_UTIL_H_
10 10
11 11 #include "compat.h"
12 12
13 13 #if PY_MAJOR_VERSION >= 3
14 14 #define IS_PY3K
15 15 #endif
16 16
17 /* clang-format off */
17 18 typedef struct {
18 19 PyObject_HEAD
19 20 char state;
20 21 int mode;
21 22 int size;
22 23 int mtime;
23 24 } dirstateTupleObject;
25 /* clang-format on */
24 26
25 27 extern PyTypeObject dirstateTupleType;
26 28 #define dirstate_tuple_check(op) (Py_TYPE(op) == &dirstateTupleType)
27 29
28 #define MIN(a, b) (((a)<(b))?(a):(b))
30 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
29 31 /* VC9 doesn't include bool and lacks stdbool.h based on my searching */
30 32 #if defined(_MSC_VER) || __STDC_VERSION__ < 199901L
31 33 #define true 1
32 34 #define false 0
33 35 typedef unsigned char bool;
34 36 #else
35 37 #include <stdbool.h>
36 38 #endif
37 39
38 40 static inline PyObject *_dict_new_presized(Py_ssize_t expected_size)
39 41 {
40 42 /* _PyDict_NewPresized expects a minused parameter, but it actually
41 43 creates a dictionary that's the nearest power of two bigger than the
42 44 parameter. For example, with the initial minused = 1000, the
43 45 dictionary created has size 1024. Of course in a lot of cases that
44 46 can be greater than the maximum load factor Python's dict object
45 47 expects (= 2/3), so as soon as we cross the threshold we'll resize
46 48 anyway. So create a dictionary that's at least 3/2 the size. */
47 49 return _PyDict_NewPresized(((1 + expected_size) / 2) * 3);
48 50 }
49 51
50 52 #endif /* _HG_UTIL_H_ */
General Comments 0
You need to be logged in to leave comments. Login now