Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace manual array copy with System.arraycopy #84

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 15 additions & 45 deletions src/main/java/com/ibm/as400/access/AS400JDBCArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -539,9 +539,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.String".equals(arrayType)) {
String[] inStringArray = (String[]) inArray;
String[] stringArray = new String[inStringArray.length];
for (int i = 0; i < inStringArray.length; i++) {
stringArray[i] = inStringArray[i];
}
System.arraycopy(inStringArray, 0, stringArray, 0, inStringArray.length);
data_ = stringArray;
} else if ("java.math.BigDecimal".equals(arrayType)
|| "java.lang.Boolean".equals(arrayType)
Expand Down Expand Up @@ -629,9 +627,7 @@ private void setArray(Object inArray) throws SQLException {
} else if ("java.lang.Integer".equals(arrayType)) {
Integer[] inIntegerArray = (Integer[]) inArray;
Integer[] shortArray = new Integer[inIntegerArray.length];
for (int i = 0; i < inIntegerArray.length; i++) {
shortArray[i] = inIntegerArray[i];
} /* for i */
System.arraycopy(inIntegerArray, 0, shortArray, 0, inIntegerArray.length);
data_ = shortArray;
} else if ("int".equals(arrayType)) {
int[] inIntArray = (int[]) inArray;
Expand Down Expand Up @@ -821,9 +817,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.Integer".equals(arrayType)) {
Integer[] inIntegerArray = (Integer[]) inArray;
Integer[] integerArray = new Integer[inIntegerArray.length];
for (int i = 0; i < inIntegerArray.length; i++) {
integerArray[i] = inIntegerArray[i];
}
System.arraycopy(inIntegerArray, 0, integerArray, 0, inIntegerArray.length);
data_ = integerArray;

} else if ("int".equals(arrayType)) {
Expand Down Expand Up @@ -1007,9 +1001,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.Long".equals(arrayType)) {
Long[] inLongArray = (Long[]) inArray;
Long[] longArray = new Long[inLongArray.length];
for (int i = 0; i < inLongArray.length; i++) {
longArray[i] = inLongArray[i];
}
System.arraycopy(inLongArray, 0, longArray, 0, inLongArray.length);
data_ = longArray;

} else if ("long".equals(arrayType)) {
Expand Down Expand Up @@ -1187,9 +1179,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.Float".equals(arrayType)) {
Float[] inFloatArray = (Float[]) inArray;
Float[] floatArray = new Float[inFloatArray.length];
for (int i = 0; i < inFloatArray.length; i++) {
floatArray[i] = inFloatArray[i];
}
System.arraycopy(inFloatArray, 0, floatArray, 0, inFloatArray.length);
data_ = floatArray;

} else if ("float".equals(arrayType)) {
Expand Down Expand Up @@ -1406,9 +1396,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.Double".equals(arrayType)) {
Double[] inDoubleArray = (Double[]) inArray;
Double[] doubleArray = new Double[inDoubleArray.length];
for (int i = 0; i < inDoubleArray.length; i++) {
doubleArray[i] = inDoubleArray[i];
}
System.arraycopy(inDoubleArray, 0, doubleArray, 0, inDoubleArray.length);
data_ = doubleArray;

} else if ("double".equals(arrayType)) {
Expand Down Expand Up @@ -1591,9 +1579,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.Double".equals(arrayType)) {
Double[] inDoubleArray = (Double[]) inArray;
Double[] doubleArray = new Double[inDoubleArray.length];
for (int i = 0; i < inDoubleArray.length; i++) {
doubleArray[i] = inDoubleArray[i];
}
System.arraycopy(inDoubleArray, 0, doubleArray, 0, inDoubleArray.length);
data_ = doubleArray;

} else if ("double".equals(arrayType)) {
Expand Down Expand Up @@ -1777,9 +1763,7 @@ private void setArray(Object inArray) throws SQLException {
"java.math.BigDecimal")) {
BigDecimal[] inBdArray = (BigDecimal[]) inArray;
BigDecimal[] bdArray = new BigDecimal[inBdArray.length];
for (int i = 0; i < inBdArray.length; i++) {
bdArray[i] = inBdArray[i];
}
System.arraycopy(inBdArray, 0, bdArray, 0, inBdArray.length);
data_ = bdArray;

} else if ("java.lang.Double".equals(arrayType)) {
Expand Down Expand Up @@ -1949,9 +1933,7 @@ private void setArray(Object inArray) throws SQLException {
if ("[B".equals(arrayType)) {
byte[][] inByteArray = (byte[][]) inArray;
byte[][] byteArray = new byte[inByteArray.length][];
for (int i = 0; i < inByteArray.length; i++) {
byteArray[i] = inByteArray[i];
}
System.arraycopy(inByteArray, 0, byteArray, 0, inByteArray.length);
data_ = byteArray;

} else {
Expand All @@ -1969,9 +1951,7 @@ private void setArray(Object inArray) throws SQLException {

Blob[] inBlobArray = (Blob[]) inArray;
Blob[] blobArray = new Blob[inBlobArray.length];
for (int i = 0; i < inBlobArray.length; i++) {
blobArray[i] = inBlobArray[i];
}
System.arraycopy(inBlobArray, 0, blobArray, 0, inBlobArray.length);
data_ = blobArray;

} else {
Expand All @@ -1991,9 +1971,7 @@ private void setArray(Object inArray) throws SQLException {

Clob[] inClobArray = (Clob[]) inArray;
Clob[] clobArray = new Clob[inClobArray.length];
for (int i = 0; i < inClobArray.length; i++) {
clobArray[i] = inClobArray[i];
}
System.arraycopy(inClobArray, 0, clobArray, 0, inClobArray.length);
data_ = clobArray;

} else {
Expand All @@ -2010,9 +1988,7 @@ private void setArray(Object inArray) throws SQLException {
if (JDUtilities.classIsInstanceOf(arrayComponentClass, "java.sql.Date")) {
Date[] inDateArray = (Date[]) inArray;
Date[] dateArray = new Date[inDateArray.length];
for (int i = 0; i < inDateArray.length; i++) {
dateArray[i] = inDateArray[i];
}
System.arraycopy(inDateArray, 0, dateArray, 0, inDateArray.length);
data_ = dateArray;

} else {
Expand Down Expand Up @@ -2064,9 +2040,7 @@ private void setArray(Object inArray) throws SQLException {
if (JDUtilities.classIsInstanceOf(arrayComponentClass, "java.sql.Time")) {
Time[] inTimeArray = (Time[]) inArray;
Time[] timeArray = new Time[inTimeArray.length];
for (int i = 0; i < inTimeArray.length; i++) {
timeArray[i] = inTimeArray[i];
}
System.arraycopy(inTimeArray, 0, timeArray, 0, inTimeArray.length);
data_ = timeArray;

} else {
Expand All @@ -2084,9 +2058,7 @@ private void setArray(Object inArray) throws SQLException {
"java.sql.Timestamp")) {
Timestamp[] inTimestampArray = (Timestamp[]) inArray;
Timestamp[] timestampArray = new Timestamp[inTimestampArray.length];
for (int i = 0; i < inTimestampArray.length; i++) {
timestampArray[i] = inTimestampArray[i];
}
System.arraycopy(inTimestampArray, 0, timestampArray, 0, inTimestampArray.length);
data_ = timestampArray;

} else {
Expand All @@ -2103,9 +2075,7 @@ private void setArray(Object inArray) throws SQLException {
if ("java.lang.Boolean".equals(arrayType)) {
Boolean[] inBooleanArray = (Boolean[]) inArray;
Boolean[] booleanArray = new Boolean[inBooleanArray.length];
for (int i = 0; i < inBooleanArray.length; i++) {
booleanArray[i] = inBooleanArray[i];
}
System.arraycopy(inBooleanArray, 0, booleanArray, 0, inBooleanArray.length);
data_ = booleanArray;
} else if ("boolean".equals(arrayType)) {
boolean[] inBooleanArray = (boolean[]) inArray;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6258,9 +6258,7 @@ public ConvTable getPackageCCSID_Converter() {
* @param newConnection
*/
void transferObjects(AS400JDBCConnectionImpl newConnection) {
for (int i =0; i< MAX_STATEMENTS_; i++) {
newConnection.assigned_[i] = assigned_[i];
}
System.arraycopy(assigned_, 0, newConnection.assigned_, 0, MAX_STATEMENTS_);
newConnection.statements_ = statements_;
statements_ = new Vector();

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/ibm/as400/access/ConvTableSingleMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,7 @@ public void updateToUnicode(int ebcdic, char unicode) {
char[] oldToUnicode = toUnicode_;

toUnicode_ = new char[oldToUnicode.length];
for (int i = 0; i < oldToUnicode.length; i++) {
toUnicode_[i] = oldToUnicode[i];
}
System.arraycopy(oldToUnicode, 0, toUnicode_, 0, oldToUnicode.length);
toUnicode_[ebcdic] = unicode;
}

Expand Down
20 changes: 4 additions & 16 deletions src/main/java/com/ibm/as400/access/DLOPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -182,31 +182,19 @@ public synchronized void setDataAuthority(String authority)
return;
if (aut.equals("*ALL"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_ALL][i];
}
System.arraycopy(basicAutMapping[BASIC_ALL], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_ALL;
} else if (aut.equals("*EXCLUDE"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_EXCLUDE][i];
}
System.arraycopy(basicAutMapping[BASIC_EXCLUDE], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_EXCLUDE;
} else if (aut.equals("*USE"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_USE][i];
}
System.arraycopy(basicAutMapping[BASIC_USE], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_USE;
} else if (aut.equals("*CHANGE"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_CHANGE][i];
}
System.arraycopy(basicAutMapping[BASIC_CHANGE], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_CHANGE;
}
else if (aut.equals("*AUTL")) // @1JU - if *AUTL, then setFromAuthorizationList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1841,9 +1841,7 @@ private static byte[] removeDoubleByteEbcdic(byte[] inBytes)
byte[] outBytes = new byte[65536];

// Just copy the control characters
for (int i = 0; i < 0x20; i++) {
outBytes[i] = inBytes[i];
}
System.arraycopy(inBytes, 0, outBytes, 0, 0x20);
int toIndex = 0x20;
boolean singleByte = true;
for (int i = 0x20; i < inBytes.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ public int read(byte[] data,
new Integer (length) },
ARGS_TO_RETURN, false );
byte [] returnDataBuffer = (byte[])rv.getArgument(0);
for (int i=0; i<data.length; i++) {
data[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, data, 0, data.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ public int read(byte[] data,
// will wait for the requested number of bytes to become available.

byte [] returnDataBuffer = (byte[])rv.getArgument(0);
for (int i=0; i<data.length; i++) {
data[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, data, 0, data.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/ibm/as400/access/JDInputStreamProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ public int read (byte[] data, int start, int length)
new Integer (length) },
ARGS_TO_RETURN, false );
byte [] returnDataBuffer = (byte[])rv.getArgument(0);
for (int i=0; i<data.length; i++) {
data[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, data, 0, data.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/com/ibm/as400/access/JDProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -2125,11 +2125,9 @@ private void readObject(java.io.ObjectInputStream in)
{
String[] temp = new String[NUMBER_OF_ATTRIBUTES_];

for(int i = 0; i < values_.length; i++)
temp[i] = values_[i];
System.arraycopy(values_, 0, temp, 0, values_.length);

for(int i = values_.length; i < NUMBER_OF_ATTRIBUTES_; i++)
temp[i] = defaults_[i];
System.arraycopy(defaults_, values_.length, temp, values_.length, NUMBER_OF_ATTRIBUTES_ - values_.length);

values_ = temp;
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/ibm/as400/access/JDReaderProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ public int read(char cbuf[],
new Integer (len) },
ARGS_TO_RETURN, false );
char[] returnDataBuffer = (char[])rv.getArgument(0);
for (int i=0; i<cbuf.length; i++) {
cbuf[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, cbuf, 0, cbuf.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,7 @@ public int read(byte data[], int dataOffset, int length)
myArgs, false);

byte [] returnDataBuffer = (byte[])rv.getArgument(0);
for (int i=0; i<data.length; i++) {
data[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, data, 0, data.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,7 @@ public int read(byte data[], int dataOffset, int length)
myArgs, false);

byte [] returnDataBuffer = (byte[])rv.getArgument(0);
for (int i=0; i<data.length; i++) {
data[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, data, 0, data.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public int read(byte data[], int dataOffset, int length)
myArgs, false);

byte [] returnDataBuffer = (byte[])rv.getArgument(0);
for (int i=0; i<data.length; i++) {
data[i] = returnDataBuffer[i];
}
System.arraycopy(returnDataBuffer, 0, data, 0, data.length);
return rv.getReturnValueInt();
}
catch (InvocationTargetException e) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/com/ibm/as400/access/QSYSObjectTypeTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,7 @@ public static String[] getSupportedObjectTypes()
{
// Create a copy, so as not to expose internal representation.
types = new String[types_.length];
for (int i=0; i<types_.length; i++) {
types[i] = types_[i];
}
System.arraycopy(types_, 0, types, 0, types_.length);
}
return types;
}
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/com/ibm/as400/access/QSYSPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -573,31 +573,19 @@ public synchronized void setObjectAuthority(String authority)
return;
if (aut.equals("*ALL"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_ALL][i];
}
System.arraycopy(basicAutMapping[BASIC_ALL], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_ALL;
} else if (aut.equals("*EXCLUDE"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_EXCLUDE][i];
}
System.arraycopy(basicAutMapping[BASIC_EXCLUDE], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_EXCLUDE;
} else if (aut.equals("*USE"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_USE][i];
}
System.arraycopy(basicAutMapping[BASIC_USE], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_USE;
} else if (aut.equals("*CHANGE"))
{
for (int i=0;i<10;i++)
{
authorities_[i] = basicAutMapping[BASIC_CHANGE][i];
}
System.arraycopy(basicAutMapping[BASIC_CHANGE], 0, authorities_, 0, 10);
objectAuthority_ = BASIC_CHANGE;
} else if (aut.equals("*AUTL")) // @A4a
{
Expand Down
10 changes: 2 additions & 8 deletions src/main/java/com/ibm/as400/access/SCS5256Writer.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,10 +451,7 @@ public void setHorizontalFormat(int NumOfChars)
}
horizontalFormat_ = NumOfChars;

for(int i=0; i< (cmd.length-1); i++)
{
cmd[i] = SHF[i];
}
System.arraycopy(SHF, 0, cmd, 0, cmd.length-1);
cmd[cmd.length-1] = (byte)NumOfChars;
addToBuffer(cmd);
}
Expand Down Expand Up @@ -484,10 +481,7 @@ public void setVerticalFormat(int NumOfLines)
}
verticalFormat_ = NumOfLines;

for(int i=0; i< (cmd.length-1); i++)
{
cmd[i] = SVF[i];
}
System.arraycopy(SVF, 0, cmd, 0, cmd.length-1);
cmd[cmd.length-1] = (byte)NumOfLines;
addToBuffer(cmd);
}
Expand Down
Loading