Module Name:    src
Committed By:   christos
Date:           Mon Nov 17 17:11:30 UTC 2014

Modified Files:
        src/sys/sys: clock.h

Log Message:
Optimize.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/sys/sys/clock.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/sys/clock.h
diff -u src/sys/sys/clock.h:1.2 src/sys/sys/clock.h:1.3
--- src/sys/sys/clock.h:1.2	Mon Nov 17 05:55:12 2014
+++ src/sys/sys/clock.h	Mon Nov 17 12:11:29 2014
@@ -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 @@ days_in_month(int m)
 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

Reply via email to