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