Skip to content

Commit bfd254d

Browse files
committed
Update release notes wrt #948, convert Math.pow() to simpler switch
1 parent 61cc6a5 commit bfd254d

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

release-notes/CREDITS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,5 +338,7 @@ Andreas Pieber (anpieber@github)
338338
(2.6.3)
339339

340340
Jesse Wilson (swankjesse@github)
341+
* Contributed #948: Support leap seconds, any number of millisecond digits for ISO-8601 Dates.
342+
(2.6.3)
341343
* Contributed #949: Report the offending substring when number parsing fails
342344
(2.6.3)

release-notes/VERSION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ Project: jackson-databind
99
#819: Add support for setting `FormatFeature` via `ObjectReader`, `ObjectWriter`
1010
#918: Add `MapperFeature.ALLOW_EXPLICIT_PROPERTY_RENAMING`
1111
(contributed by David H)
12-
#933:Close some gaps to allow using the tryToResolveUnresolved flows
12+
#933: Close some gaps to allow using the tryToResolveUnresolved flows
13+
#948: Support leap seconds, any number of millisecond digits for ISO-8601 Dates.
14+
(contributed by Jesse W)
1315

1416
2.6.3 (not yet released)
1517

src/main/java/com/fasterxml/jackson/databind/util/ISO8601Utils.java

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,17 @@ public static Date parse(String date, ParsePosition pos) throws ParseException {
207207
int endOffset = indexOfNonDigit(date, offset + 1); // assume at least one digit
208208
int parseEndOffset = Math.min(endOffset, offset + 3); // parse up to 3 digits
209209
int fraction = parseInt(date, offset, parseEndOffset);
210-
milliseconds = (int) (Math.pow(10, 3 - (parseEndOffset - offset)) * fraction);
210+
// compensate for "missing" digits
211+
switch (parseEndOffset - offset) { // number of digits parsed
212+
case 2:
213+
milliseconds = fraction * 10;
214+
break;
215+
case 1:
216+
milliseconds = fraction * 100;
217+
break;
218+
default:
219+
milliseconds = fraction;
220+
}
211221
offset = endOffset;
212222
}
213223
}
@@ -357,4 +367,44 @@ private static int indexOfNonDigit(String string, int offset) {
357367
}
358368
return string.length();
359369
}
370+
371+
public static void main(String[] args)
372+
{
373+
final int REPS = 250000;
374+
while (true) {
375+
long start = System.currentTimeMillis();
376+
int resp = test1(REPS, 3);
377+
long msecs = System.currentTimeMillis() - start;
378+
System.out.println("Pow ("+resp+") -> "+msecs+" ms");
379+
380+
start = System.currentTimeMillis();
381+
resp = test2(REPS, 3);
382+
msecs = System.currentTimeMillis() - start;
383+
System.out.println("Iter ("+resp+") -> "+msecs+" ms");
384+
}
385+
}
386+
387+
static int test1(int reps, int pow)
388+
{
389+
int resp = 3;
390+
while (--reps >= 0) {
391+
resp = (int) Math.pow(10, pow);
392+
}
393+
return resp;
394+
}
395+
396+
static int test2(int reps, int pow)
397+
{
398+
int resp = 3;
399+
while (--reps >= 0) {
400+
resp = 10;
401+
int p = pow;
402+
403+
while (--p > 0) {
404+
resp *= 10;
405+
}
406+
}
407+
return resp;
408+
}
360409
}
410+

0 commit comments

Comments
 (0)