Commit 6ea41dcc authored by Bruce Momjian's avatar Bruce Momjian

Patch for jdbc2 ResultSet.java. Looks like performance improvement.

Joseph Shraibman
parent 1834987f
...@@ -134,7 +134,6 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -134,7 +134,6 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
{ {
//release resources held (memory for tuples) //release resources held (memory for tuples)
if(rows!=null) { if(rows!=null) {
rows.setSize(0);
rows=null; rows=null;
} }
} }
...@@ -710,7 +709,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -710,7 +709,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
{ {
int i; int i;
for (i = 0 ; i < fields.length; ++i) final int flen = fields.length;
for (i = 0 ; i < flen; ++i)
if (fields[i].getName().equalsIgnoreCase(columnName)) if (fields[i].getName().equalsIgnoreCase(columnName))
return (i+1); return (i+1);
throw new PSQLException ("postgresql.res.colname",columnName); throw new PSQLException ("postgresql.res.colname",columnName);
...@@ -726,11 +726,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -726,11 +726,13 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
if (index==0) if (index==0)
throw new SQLException("Cannot move to index of 0"); throw new SQLException("Cannot move to index of 0");
final int rows_size = rows.size();
//if index<0, count from the end of the result set, but check //if index<0, count from the end of the result set, but check
//to be sure that it is not beyond the first index //to be sure that it is not beyond the first index
if (index<0) if (index<0)
if (index>=-rows.size()) if (index > -rows_size)
internalIndex=rows.size()+index; internalIndex = rows_size+index;
else { else {
beforeFirst(); beforeFirst();
return false; return false;
...@@ -739,7 +741,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -739,7 +741,7 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
//must be the case that index>0, //must be the case that index>0,
//find the correct place, assuming that //find the correct place, assuming that
//the index is not too large //the index is not too large
if (index<=rows.size()) if (index <= rows_size)
internalIndex = index-1; internalIndex = index-1;
else { else {
afterLast(); afterLast();
...@@ -753,8 +755,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -753,8 +755,9 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public void afterLast() throws SQLException public void afterLast() throws SQLException
{ {
if (rows.size() > 0) final int rows_size = rows.size();
current_row = rows.size(); if (rows_size > 0)
current_row = rows_size;
} }
public void beforeFirst() throws SQLException public void beforeFirst() throws SQLException
...@@ -967,7 +970,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -967,7 +970,8 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public boolean isAfterLast() throws SQLException public boolean isAfterLast() throws SQLException
{ {
return (current_row >= rows.size() && rows.size() > 0); final int rows_size = rows.size();
return (current_row >= rows_size && rows_size > 0);
} }
public boolean isBeforeFirst() throws SQLException public boolean isBeforeFirst() throws SQLException
...@@ -982,16 +986,18 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -982,16 +986,18 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
public boolean isLast() throws SQLException public boolean isLast() throws SQLException
{ {
return (current_row == rows.size() -1 && rows.size() > 0); final int rows_size = rows.size();
return (current_row == rows_size -1 && rows_size > 0);
} }
public boolean last() throws SQLException public boolean last() throws SQLException
{ {
if (rows.size() <= 0) final int rows_size = rows.size();
return false; if (rows_size <= 0)
current_row = rows.size() - 1; return false;
this_row = (byte [][])rows.elementAt(current_row); current_row = rows_size - 1;
return true; this_row = (byte [][])rows.elementAt(current_row);
return true;
} }
public void moveToCurrentRow() throws SQLException public void moveToCurrentRow() throws SQLException
...@@ -1480,4 +1486,3 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu ...@@ -1480,4 +1486,3 @@ public class ResultSet extends org.postgresql.ResultSet implements java.sql.Resu
} }
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment