Merge branch 'master' into v2.1

This commit is contained in:
Mike Pall
2022-12-22 00:52:04 +01:00
15 changed files with 43 additions and 40 deletions

View File

@@ -124,19 +124,19 @@ static StrScanFmt strscan_hex(const uint8_t *p, TValue *o,
case STRSCAN_INT:
if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg &&
!(x == 0 && neg)) {
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_INT; /* Fast path for 32 bit integers. */
}
if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }
/* fallthrough */
case STRSCAN_U32:
if (dig > 8) return STRSCAN_ERROR;
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_U32;
case STRSCAN_I64:
case STRSCAN_U64:
if (dig > 16) return STRSCAN_ERROR;
o->u64 = neg ? (uint64_t)-(int64_t)x : x;
o->u64 = neg ? ~x+1u : x;
return fmt;
default:
break;
@@ -168,12 +168,12 @@ static StrScanFmt strscan_oct(const uint8_t *p, TValue *o,
/* fallthrough */
case STRSCAN_U32:
if ((x >> 32)) return STRSCAN_ERROR;
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~(uint32_t)x+1u) : (int32_t)x;
break;
default:
case STRSCAN_I64:
case STRSCAN_U64:
o->u64 = neg ? (uint64_t)-(int64_t)x : x;
o->u64 = neg ? ~x+1u : x;
break;
}
return fmt;
@@ -229,18 +229,18 @@ static StrScanFmt strscan_dec(const uint8_t *p, TValue *o,
switch (fmt) {
case STRSCAN_INT:
if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_INT; /* Fast path for 32 bit integers. */
}
if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; goto plainnumber; }
/* fallthrough */
case STRSCAN_U32:
if ((x >> 32) != 0) return STRSCAN_ERROR;
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_U32;
case STRSCAN_I64:
case STRSCAN_U64:
o->u64 = neg ? (uint64_t)-(int64_t)x : x;
o->u64 = neg ? ~x+1u : x;
return fmt;
default:
plainnumber: /* Fast path for plain numbers < 2^63. */
@@ -348,18 +348,18 @@ static StrScanFmt strscan_bin(const uint8_t *p, TValue *o,
switch (fmt) {
case STRSCAN_INT:
if (!(opt & STRSCAN_OPT_TONUM) && x < 0x80000000u+neg) {
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_INT; /* Fast path for 32 bit integers. */
}
if (!(opt & STRSCAN_OPT_C)) { fmt = STRSCAN_NUM; break; }
/* fallthrough */
case STRSCAN_U32:
if (dig > 32) return STRSCAN_ERROR;
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_U32;
case STRSCAN_I64:
case STRSCAN_U64:
o->u64 = neg ? (uint64_t)-(int64_t)x : x;
o->u64 = neg ? ~x+1u : x;
return fmt;
default:
break;
@@ -468,7 +468,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o,
if (xx >= STRSCAN_MAXEXP) return STRSCAN_ERROR;
p++;
}
ex += negx ? -(int32_t)xx : (int32_t)xx;
ex += negx ? (int32_t)(~xx+1u) : (int32_t)xx;
}
/* Parse suffix. */
@@ -507,7 +507,7 @@ StrScanFmt lj_strscan_scan(const uint8_t *p, MSize len, TValue *o,
o->n = -0.0;
return STRSCAN_NUM;
} else {
o->i = neg ? -(int32_t)x : (int32_t)x;
o->i = neg ? (int32_t)(~x+1u) : (int32_t)x;
return STRSCAN_INT;
}
}