Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/sys Optimize.



details:   https://anonhg.NetBSD.org/src/rev/cc40bd40b1d8
branches:  trunk
changeset: 333825:cc40bd40b1d8
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Nov 17 17:11:29 2014 +0000

description:
Optimize.

diffstat:

 sys/sys/clock.h |  42 +++++++++++++++++-------------------------
 1 files changed, 17 insertions(+), 25 deletions(-)

diffs (71 lines):

diff -r cf9132aa75fd -r cc40bd40b1d8 sys/sys/clock.h
--- a/sys/sys/clock.h   Mon Nov 17 16:55:05 2014 +0000
+++ b/sys/sys/clock.h   Mon Nov 17 17:11:29 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: clock.h,v 1.2 2014/11/17 10:55:12 joerg Exp $  */
+/*     $NetBSD: clock.h,v 1.3 2014/11/17 17:11:29 christos Exp $       */
 
 /*-
  * Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -32,12 +32,6 @@
 #ifndef _SYS_CLOCK_H_
 #define _SYS_CLOCK_H_
 
-#if !defined(_KERNEL) && !defined(_STANDALONE)
-#include <errno.h>
-#else
-#include <sys/errno.h>
-#endif
-
 /* Some handy constants. */
 #define SECS_PER_MINUTE                60
 #define SECS_PER_HOUR          3600
@@ -54,14 +48,16 @@
 static inline int
 days_in_month(int m)
 {
-       static const int month_days[12] = {
-               31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
-       };
-
-       if (__predict_false(m < 1 || m > 12))
-               return EINVAL;
-
-       return month_days[m - 1];
+       switch (m) {
+       case 2:
+               return 28;
+       case 4: case 6: case 9: case 11:
+               return 30;
+       case 1: case 3: case 5: case 7: case 8: case 10: case 12:
+               return 31;
+       default:
+               return -1;
+       }
 }
 
 /*
@@ -75,17 +71,13 @@
 static inline int
 is_leap_year(uint64_t year)
 {
-       int rv = 0;
+       if ((year & 3) != 0)
+               return 0;
 
-       if ((year & 3) == 0) {
-               rv = 1;
-               if (__predict_false((year % 100) == 0)) {
-                       rv = 0;
-                       if (__predict_false((year % 400) == 0))
-                               rv = 1;
-               }
-       }
-       return rv;
+       if (__predict_false((year % 100) != 0))
+               return 1;
+
+       return __predict_false((year % 400) == 0);
 }
 
 static inline int



Home | Main Index | Thread Index | Old Index