MCPcopy Create free account
hub / github.com/questdb/questdb / parseLong0

Method parseLong0

core/src/main/java/io/questdb/std/Numbers.java:2935–2985  ·  view source on GitHub ↗
(CharSequence sequence, final int p, int lim)

Source from the content-addressed store, hash-verified

2933 }
2934
2935 private static long parseLong0(CharSequence sequence, final int p, int lim) throws NumericException {
2936 if (lim == p) {
2937 throw NumericException.instance().put("empty long string");
2938 }
2939
2940 boolean negative = sequence.charAt(p) == '-';
2941
2942 int i = p;
2943 if (negative) {
2944 i++;
2945 }
2946
2947 if (i >= lim) {
2948 throw NumericException.instance().put("empty long string");
2949 }
2950
2951 int digitCounter = 0;
2952 long val = 0;
2953 for (; i < lim; i++) {
2954 int c = sequence.charAt(i);
2955 switch (c | 32) {
2956 case 'l':
2957 if (i == 0 || i + 1 < lim) {
2958 throw NumericException.instance().put("invalid long format: ").put(sequence, p, lim);
2959 }
2960 break;
2961 case 127: // '_'
2962 if (digitCounter == 0) {
2963 throw NumericException.instance().put("invalid long format: ").put(sequence, p, lim);
2964 }
2965 digitCounter = 0;
2966 break;
2967 default:
2968 if (c < '0' || c > '9') {
2969 throw NumericException.instance().put("invalid character in long: ").put(sequence, p, lim);
2970 }
2971 // val * 10 + (c - '0')
2972 long r = (val << 3) + (val << 1) - (c - '0');
2973 if (r > val) {
2974 throw NumericException.instance().put("long overflow: ").put(sequence, p, lim);
2975 }
2976 val = r;
2977 digitCounter++;
2978 }
2979 }
2980
2981 if ((val == Long.MIN_VALUE && !negative) || digitCounter == 0) {
2982 throw NumericException.instance().put("invalid long format: ").put(sequence, p, lim);
2983 }
2984 return negative ? val : -val;
2985 }
2986
2987 private static short parseShort0(CharSequence sequence, final int p, int lim) throws NumericException {
2988 if (lim == p) {

Callers 2

parseLongMethod · 0.95
parseLongQuietMethod · 0.95

Calls 3

instanceMethod · 0.95
putMethod · 0.65
charAtMethod · 0.45

Tested by

no test coverage detected