Skip to content

Commit c0749ef

Browse files
committed
Prefix const ZEND_TIME_* & inline zend_time_real_sec
1 parent bd5fb4c commit c0749ef

2 files changed

Lines changed: 12 additions & 15 deletions

File tree

Zend/zend_time.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@
1616

1717
#include "zend_time.h"
1818

19-
/* Current real/wall-time in seconds */
20-
ZEND_API time_t zend_time_real_sec(void) {
21-
return time(NULL);
22-
}
23-
2419
ZEND_API void zend_time_real_spec(struct timespec *ts) {
2520
#if defined(HAVE_CLOCK_GETTIME)
2621

Zend/zend_time.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
# define tv_usec_t long
3838
#endif
3939

40-
#define ZEND_MILLI_IN_SEC 1000U
41-
#define ZEND_MICRO_IN_SEC 1000000U
40+
#define ZEND_TIME_MILLI_IN_SEC 1000U
41+
#define ZEND_TIME_MICRO_IN_SEC 1000000U
4242

4343
BEGIN_EXTERN_C()
4444

@@ -50,26 +50,26 @@ static zend_always_inline void zend_time_sec2val(time_t s, struct timeval *tv) {
5050

5151
/* Assign microseconds to timeval */
5252
static zend_always_inline void zend_time_usec2val(int64_t usec, struct timeval *tv) {
53-
tv->tv_sec = (tv_sec_t) (usec / ZEND_MICRO_IN_SEC);
54-
tv->tv_usec = (tv_usec_t) (usec % ZEND_MICRO_IN_SEC);
53+
tv->tv_sec = (tv_sec_t) (usec / ZEND_TIME_MICRO_IN_SEC);
54+
tv->tv_usec = (tv_usec_t) (usec % ZEND_TIME_MICRO_IN_SEC);
5555

5656
if (UNEXPECTED(tv->tv_usec < 0)) {
57-
tv->tv_usec += ZEND_MICRO_IN_SEC;
57+
tv->tv_usec += ZEND_TIME_MICRO_IN_SEC;
5858
tv->tv_sec -= 1;
5959
}
6060
}
6161

6262
/* Assign double (seconds) to timeval */
6363
static zend_always_inline void zend_time_dbl2val(double s, struct timeval *tv) {
6464
tv->tv_sec = (tv_sec_t) s;
65-
tv->tv_usec = (tv_usec_t) ((s - tv->tv_sec) * ZEND_MICRO_IN_SEC);
65+
tv->tv_usec = (tv_usec_t) ((s - tv->tv_sec) * ZEND_TIME_MICRO_IN_SEC);
6666

6767
if (UNEXPECTED(tv->tv_usec < 0)) {
68-
tv->tv_usec += ZEND_MICRO_IN_SEC;
68+
tv->tv_usec += ZEND_TIME_MICRO_IN_SEC;
6969
tv->tv_sec -= 1;
70-
} else if (UNEXPECTED(tv->tv_usec >= ZEND_MICRO_IN_SEC)) {
70+
} else if (UNEXPECTED(tv->tv_usec >= ZEND_TIME_MICRO_IN_SEC)) {
7171
// rare, but protects against rounding up to exactly 1 second
72-
tv->tv_usec -= ZEND_MICRO_IN_SEC;
72+
tv->tv_usec -= ZEND_TIME_MICRO_IN_SEC;
7373
tv->tv_sec += 1;
7474
}
7575
}
@@ -81,7 +81,9 @@ static zend_always_inline void zend_time_val2spec(struct timeval tv, struct time
8181
}
8282

8383
/* Current real/wall-time in seconds */
84-
ZEND_API time_t zend_time_real_sec(void);
84+
static zend_always_inline time_t zend_time_real_sec(void) {
85+
return time(NULL);
86+
}
8587

8688
/* Current real/wall-time in up-to nano seconds */
8789
ZEND_API void zend_time_real_spec(struct timespec *ts);

0 commit comments

Comments
 (0)