Skip to content

Commit

Permalink
Changes to improve performance in web events when a lot of data are i…
Browse files Browse the repository at this point in the history
…n the page

Issue: 107443
  • Loading branch information
iroqueta committed Mar 26, 2024
1 parent 373ff7b commit abbd1f5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 34 deletions.
26 changes: 13 additions & 13 deletions common/src/main/java/com/genexus/CommonUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public Object initialValue()

public static String removeAllQuotes(String fileName)
{
StringBuffer out = new StringBuffer();
StringBuilder out = new StringBuilder();
int len = fileName.length();
for (int i = 0; i < len; i++)
if (fileName.charAt(i) != '"')
Expand Down Expand Up @@ -993,7 +993,7 @@ public static String strReplace(String s, String subString, String replacement)
return s;

int index, start, subLength;
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
subLength = subString.length();

for (start = 0, index = s.indexOf(subString, start); index >= 0; start = index + subLength, index = s.indexOf(subString, start))
Expand Down Expand Up @@ -1050,7 +1050,7 @@ public static String replicate (char character, int size)
if (size <= 0)
return "";

StringBuffer ret = new StringBuffer(size);
StringBuilder ret = new StringBuilder(size);

for (int i = 0; i < size; i++)
{
Expand All @@ -1065,7 +1065,7 @@ public static String replicate (String character, int size, int a)
if (size <= 0)
return "";

StringBuffer ret = new StringBuffer(size);
StringBuilder ret = new StringBuilder(size);

for (int i = 0; i < size; i++)
{
Expand Down Expand Up @@ -1188,7 +1188,7 @@ public static long lval(String text)
}
catch (Exception e)
{
StringBuffer out = new StringBuffer();
StringBuilder out = new StringBuilder();

boolean first = true;
int len = text.length();
Expand Down Expand Up @@ -1252,8 +1252,8 @@ public static BigDecimal decimalVal(String text, String sDSep)
return BigDecimal.ZERO;
}

private static StringBuffer extractNumericStringValue(String text, String sDSep) {
StringBuffer out = new StringBuffer();
private static StringBuilder extractNumericStringValue(String text, String sDSep) {
StringBuilder out = new StringBuilder();

char dSep = (sDSep.length() > 0) ? sDSep.charAt(0) : '.';
boolean point = false;
Expand Down Expand Up @@ -1820,7 +1820,7 @@ protected static boolean in(String text , char c)

public static String getTimeFormat(String time)
{
StringBuffer ret = new StringBuffer(time);
StringBuilder ret = new StringBuilder(time);
char hora;
boolean app = false;
char append = ' ';
Expand Down Expand Up @@ -2296,7 +2296,7 @@ public static boolean contains(Object []arr, Object item)
public static String format(String value, String v1, String v2, String v3, String v4, String v5, String v6, String v7, String v8, String v9)
{
String[] vs = {v1, v2, v3, v4, v5, v6, v7, v8, v9};
StringBuffer stringBuilder = new StringBuffer();
StringBuilder stringBuilder = new StringBuilder();
if (value != null && !value.equals(""))
{
StringTokenizer tokenizer = new StringTokenizer(value, "%", false);
Expand Down Expand Up @@ -2515,7 +2515,7 @@ public static String strUnexponentString(String num)
int point = num.indexOf('.');
int scale = num.length() - (point == -1 ? num.length () : point + 1) - scaleAdj;

StringBuffer val = new StringBuffer(point == -1 ? num : num.substring(0, point) + num.substring (point + 1));
StringBuilder val = new StringBuilder(point == -1 ? num : num.substring(0, point) + num.substring (point + 1));

// correct for negative scale as per BigDecimal javadoc
for(; scale<0; scale++)
Expand Down Expand Up @@ -2844,7 +2844,7 @@ public static String strori(double val, int digits, int decimals)
if (decimals < 0) decimals = 0;
if (digits < 0) digits = 0;

StringBuffer b = new StringBuffer();
StringBuilder b = new StringBuilder();
boolean hasSign = (val < 0);

if (hasSign)
Expand Down Expand Up @@ -3054,7 +3054,7 @@ public static String addLastPathSeparator(String dir) {
}

public static String quoteString(String in, boolean entities8bit, boolean encodeQuotes) {
StringBuffer out = new StringBuffer();
StringBuilder out = new StringBuilder();
for (int i = 0; i < in.length(); i++)
{
char currentChar = in.charAt(i);
Expand Down Expand Up @@ -3313,7 +3313,7 @@ public final static String hashtable2query(Hashtable hashtable)
if (hashtable == null)
return null;

StringBuffer qbuf = new StringBuffer();
StringBuilder qbuf = new StringBuilder();
for (Enumeration en = hashtable.keys(); en.hasMoreElements();) {
Object key = en.nextElement();
qbuf.append((key == null ? null : URLEncode((String)key,"UTF-8")) + "=" +
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/java/json/org/json/JSONArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public boolean isNull(int index) {
*/
public String join(String separator) throws JSONException {
int len = length();
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();

for (int i = 0; i < len; i += 1) {
if (i > 0) {
Expand Down Expand Up @@ -820,7 +820,7 @@ String toString(int indentFactor, int indent) throws JSONException {
return "[]";
}
int i;
StringBuffer sb = new StringBuffer("[");
StringBuilder sb = new StringBuilder("[");
if (len == 1) {
sb.append(JSONObject.valueToString(this.myArrayList.get(0),
indentFactor, indent));
Expand Down
26 changes: 12 additions & 14 deletions common/src/main/java/json/org/json/JSONObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,7 @@ public String toString() {
* The hash map where the JSONObject's properties are kept.
*/
private HashMap<String, Object> myHashMap;
private ArrayList<String> nameIndexList;


private ArrayList<String> nameIndexList;

/**
* It is sometimes more convenient and less ambiguous to have a
Expand All @@ -148,7 +146,7 @@ public String toString() {
*/
public JSONObject() {
this.myHashMap = new HashMap<>();
this.nameIndexList = new ArrayList<>();
this.nameIndexList = new ArrayList<>();
}


Expand Down Expand Up @@ -238,9 +236,9 @@ public JSONObject(Map map) {
this.myHashMap = (map == null) ?
new HashMap<>() :
new HashMap<>(map);
this.nameIndexList = (map == null) ?
new ArrayList<>():
new ArrayList<>(map.keySet());
this.nameIndexList = (map == null) ?
new ArrayList<>():
new ArrayList<>(map.keySet());
}


Expand Down Expand Up @@ -533,7 +531,7 @@ public boolean isNull(String key) {
* @return An iterator of the keys.
*/
public Iterator<String> keys() {
return this.nameIndexList.iterator();
return this.nameIndexList.iterator();
}


Expand All @@ -552,7 +550,7 @@ public int length() {
*/
public void clear() {
this.myHashMap.clear();
this.nameIndexList.clear();
this.nameIndexList.clear();
}


Expand Down Expand Up @@ -950,7 +948,7 @@ public static String quote(String string) {
char c = 0;
int i;
int len = string.length();
StringBuffer sb = new StringBuffer(len + 4);
StringBuilder sb = new StringBuilder(len + 4);
String t;

sb.append('"');
Expand Down Expand Up @@ -1004,8 +1002,8 @@ public static String quote(String string) {
* or null if there was no value.
*/
public Object remove(String key) {
if (this.nameIndexList.contains(key))
this.nameIndexList.remove(key);
if (this.nameIndexList.contains(key))
this.nameIndexList.remove(key);
return this.myHashMap.remove(key);
}

Expand Down Expand Up @@ -1066,7 +1064,7 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
public String toString() {
try {
Iterator keys = keys();
StringBuffer sb = new StringBuffer("{");
StringBuilder sb = new StringBuilder("{");

while (keys.hasNext()) {
if (sb.length() > 1) {
Expand Down Expand Up @@ -1122,7 +1120,7 @@ String toString(int indentFactor, int indent) throws JSONException {
return "{}";
}
Iterator keys = keys();
StringBuffer sb = new StringBuffer("{");
StringBuilder sb = new StringBuilder("{");
int newindent = indent + indentFactor;
Object o;
if (n == 1) {
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/json/org/json/JSONTokener.java
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public char nextClean() throws JSONException {
*/
public String nextString(char quote) throws JSONException {
char c;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (;;) {
c = next();
switch (c) {
Expand Down Expand Up @@ -284,7 +284,7 @@ public String nextTo(char d) {
*/
public String nextTo(String delimiters) {
char c;
StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
for (;;) {
c = next();
if (delimiters.indexOf(c) >= 0 || c == 0 ||
Expand Down Expand Up @@ -331,7 +331,7 @@ public Object nextValue() throws JSONException {
* formatting character.
*/

StringBuffer sb = new StringBuffer();
StringBuilder sb = new StringBuilder();
char b = c;
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
sb.append(c);
Expand Down
5 changes: 3 additions & 2 deletions java/src/main/java/com/genexus/internet/HttpRequestWeb.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.genexus.PrivateUtilities;
import com.genexus.WrapperUtils;
import com.genexus.webpanels.HttpContextWeb;
import org.apache.commons.io.IOUtils;

public class HttpRequestWeb extends HttpRequest
{
Expand Down Expand Up @@ -62,8 +63,8 @@ public String getString()
String requestEncoding = "UTF-8";
if (httpContext.getRequest().getCharacterEncoding() != null && httpContext.getRequest().getCharacterEncoding().length() > 0)
requestEncoding = httpContext.getRequest().getCharacterEncoding();
return new String(PrivateUtilities.readToByteArray(getInputStream()), requestEncoding);

return new String(IOUtils.toByteArray(getInputStream()), requestEncoding);
}
catch (IOException e)
{
Expand Down

0 comments on commit abbd1f5

Please sign in to comment.