mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8281146: Replace StringCoding.hasNegatives with countPositives
Co-authored-by: Lutz Schmidt <lucy@openjdk.org> Co-authored-by: Martin Doerr <mdoerr@openjdk.org> Reviewed-by: kvn, lucy, rriggs
This commit is contained in:
parent
249d553659
commit
beedae1141
36 changed files with 552 additions and 335 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2000, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -34,14 +34,27 @@ class StringCoding {
|
|||
|
||||
private StringCoding() { }
|
||||
|
||||
@IntrinsicCandidate
|
||||
public static boolean hasNegatives(byte[] ba, int off, int len) {
|
||||
for (int i = off; i < off + len; i++) {
|
||||
return countPositives(ba, off, len) != len;
|
||||
}
|
||||
|
||||
/**
|
||||
* Count the number of leading positive bytes in the range.
|
||||
*
|
||||
* @implSpec the implementation must return len if there are no negative
|
||||
* bytes in the range. If there are negative bytes, the implementation must return
|
||||
* a value that is less than or equal to the index of the first negative byte
|
||||
* in the range.
|
||||
*/
|
||||
@IntrinsicCandidate
|
||||
public static int countPositives(byte[] ba, int off, int len) {
|
||||
int limit = off + len;
|
||||
for (int i = off; i < limit; i++) {
|
||||
if (ba[i] < 0) {
|
||||
return true;
|
||||
return i - off;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return len;
|
||||
}
|
||||
|
||||
@IntrinsicCandidate
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue