@@ -455,6 +455,24 @@ static int c_valid_civil_p(int, int, int, double,
455455/* Check if using pure Gregorian calendar (sg == -Infinity) */
456456#define c_gregorian_only_p (sg ) (isinf(sg) && (sg) < 0)
457457
458+ /*
459+ * Fast path macros for pure Gregorian calendar.
460+ * Sets *rjd to the JD value, *ns to 1 (new style), and returns.
461+ */
462+ #define GREGORIAN_JD_FAST_PATH_RET (sg , jd_expr , rjd , ns ) \
463+ if (c_gregorian_only_p(sg)) { \
464+ *(rjd) = (jd_expr); \
465+ *(ns) = 1; \
466+ return 1; \
467+ }
468+
469+ #define GREGORIAN_JD_FAST_PATH (sg , jd_expr , rjd , ns ) \
470+ if (c_gregorian_only_p(sg)) { \
471+ *(rjd) = (jd_expr); \
472+ *(ns) = 1; \
473+ return; \
474+ }
475+
458476/* Forward declarations for Neri-Schneider optimized functions */
459477static int c_gregorian_civil_to_jd (int y , int m , int d );
460478static void c_gregorian_jd_to_civil (int jd , int * ry , int * rm , int * rd );
@@ -468,12 +486,7 @@ c_find_fdoy(int y, double sg, int *rjd, int *ns)
468486{
469487 int d , rm , rd ;
470488
471- /* Fast path: pure Gregorian calendar */
472- if (c_gregorian_only_p (sg )) {
473- * rjd = c_gregorian_fdoy (y );
474- * ns = 1 ;
475- return 1 ;
476- }
489+ GREGORIAN_JD_FAST_PATH_RET (sg , c_gregorian_fdoy (y ), rjd , ns );
477490
478491 /* Keep existing loop for Julian/reform period */
479492 for (d = 1 ; d < 31 ; d ++ )
@@ -487,12 +500,7 @@ c_find_ldoy(int y, double sg, int *rjd, int *ns)
487500{
488501 int i , rm , rd ;
489502
490- /* Fast path: pure Gregorian calendar */
491- if (c_gregorian_only_p (sg )) {
492- * rjd = c_gregorian_ldoy (y );
493- * ns = 1 ;
494- return 1 ;
495- }
503+ GREGORIAN_JD_FAST_PATH_RET (sg , c_gregorian_ldoy (y ), rjd , ns );
496504
497505 /* Keep existing loop for Julian/reform period */
498506 for (i = 0 ; i < 30 ; i ++ )
@@ -520,12 +528,7 @@ c_find_ldom(int y, int m, double sg, int *rjd, int *ns)
520528{
521529 int i , rm , rd ;
522530
523- /* Fast path: pure Gregorian calendar */
524- if (c_gregorian_only_p (sg )) {
525- * rjd = c_gregorian_ldom_jd (y , m );
526- * ns = 1 ;
527- return 1 ;
528- }
531+ GREGORIAN_JD_FAST_PATH_RET (sg , c_gregorian_ldom_jd (y , m ), rjd , ns );
529532
530533 /* Keep existing loop for Julian/reform period */
531534 for (i = 0 ; i < 30 ; i ++ )
@@ -539,12 +542,7 @@ c_civil_to_jd(int y, int m, int d, double sg, int *rjd, int *ns)
539542{
540543 int jd ;
541544
542- /* Fast path: pure Gregorian calendar */
543- if (c_gregorian_only_p (sg )) {
544- * rjd = c_gregorian_civil_to_jd (y , m , d );
545- * ns = 1 ;
546- return ;
547- }
545+ GREGORIAN_JD_FAST_PATH (sg , c_gregorian_civil_to_jd (y , m , d ), rjd , ns );
548546
549547 /* Calculate Gregorian JD using optimized algorithm */
550548 jd = c_gregorian_civil_to_jd (y , m , d );
0 commit comments