Skip to content

Commit abbd1f5

Browse files
committed
Changes to improve performance in web events when a lot of data are in the page
Issue: 107443
1 parent 373ff7b commit abbd1f5

File tree

5 files changed

+33
-34
lines changed

5 files changed

+33
-34
lines changed

common/src/main/java/com/genexus/CommonUtil.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public Object initialValue()
167167

168168
public static String removeAllQuotes(String fileName)
169169
{
170-
StringBuffer out = new StringBuffer();
170+
StringBuilder out = new StringBuilder();
171171
int len = fileName.length();
172172
for (int i = 0; i < len; i++)
173173
if (fileName.charAt(i) != '"')
@@ -993,7 +993,7 @@ public static String strReplace(String s, String subString, String replacement)
993993
return s;
994994

995995
int index, start, subLength;
996-
StringBuffer buf = new StringBuffer();
996+
StringBuilder buf = new StringBuilder();
997997
subLength = subString.length();
998998

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

1053-
StringBuffer ret = new StringBuffer(size);
1053+
StringBuilder ret = new StringBuilder(size);
10541054

10551055
for (int i = 0; i < size; i++)
10561056
{
@@ -1065,7 +1065,7 @@ public static String replicate (String character, int size, int a)
10651065
if (size <= 0)
10661066
return "";
10671067

1068-
StringBuffer ret = new StringBuffer(size);
1068+
StringBuilder ret = new StringBuilder(size);
10691069

10701070
for (int i = 0; i < size; i++)
10711071
{
@@ -1188,7 +1188,7 @@ public static long lval(String text)
11881188
}
11891189
catch (Exception e)
11901190
{
1191-
StringBuffer out = new StringBuffer();
1191+
StringBuilder out = new StringBuilder();
11921192

11931193
boolean first = true;
11941194
int len = text.length();
@@ -1252,8 +1252,8 @@ public static BigDecimal decimalVal(String text, String sDSep)
12521252
return BigDecimal.ZERO;
12531253
}
12541254

1255-
private static StringBuffer extractNumericStringValue(String text, String sDSep) {
1256-
StringBuffer out = new StringBuffer();
1255+
private static StringBuilder extractNumericStringValue(String text, String sDSep) {
1256+
StringBuilder out = new StringBuilder();
12571257

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

18211821
public static String getTimeFormat(String time)
18221822
{
1823-
StringBuffer ret = new StringBuffer(time);
1823+
StringBuilder ret = new StringBuilder(time);
18241824
char hora;
18251825
boolean app = false;
18261826
char append = ' ';
@@ -2296,7 +2296,7 @@ public static boolean contains(Object []arr, Object item)
22962296
public static String format(String value, String v1, String v2, String v3, String v4, String v5, String v6, String v7, String v8, String v9)
22972297
{
22982298
String[] vs = {v1, v2, v3, v4, v5, v6, v7, v8, v9};
2299-
StringBuffer stringBuilder = new StringBuffer();
2299+
StringBuilder stringBuilder = new StringBuilder();
23002300
if (value != null && !value.equals(""))
23012301
{
23022302
StringTokenizer tokenizer = new StringTokenizer(value, "%", false);
@@ -2515,7 +2515,7 @@ public static String strUnexponentString(String num)
25152515
int point = num.indexOf('.');
25162516
int scale = num.length() - (point == -1 ? num.length () : point + 1) - scaleAdj;
25172517

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

25202520
// correct for negative scale as per BigDecimal javadoc
25212521
for(; scale<0; scale++)
@@ -2844,7 +2844,7 @@ public static String strori(double val, int digits, int decimals)
28442844
if (decimals < 0) decimals = 0;
28452845
if (digits < 0) digits = 0;
28462846

2847-
StringBuffer b = new StringBuffer();
2847+
StringBuilder b = new StringBuilder();
28482848
boolean hasSign = (val < 0);
28492849

28502850
if (hasSign)
@@ -3054,7 +3054,7 @@ public static String addLastPathSeparator(String dir) {
30543054
}
30553055

30563056
public static String quoteString(String in, boolean entities8bit, boolean encodeQuotes) {
3057-
StringBuffer out = new StringBuffer();
3057+
StringBuilder out = new StringBuilder();
30583058
for (int i = 0; i < in.length(); i++)
30593059
{
30603060
char currentChar = in.charAt(i);
@@ -3313,7 +3313,7 @@ public final static String hashtable2query(Hashtable hashtable)
33133313
if (hashtable == null)
33143314
return null;
33153315

3316-
StringBuffer qbuf = new StringBuffer();
3316+
StringBuilder qbuf = new StringBuilder();
33173317
for (Enumeration en = hashtable.keys(); en.hasMoreElements();) {
33183318
Object key = en.nextElement();
33193319
qbuf.append((key == null ? null : URLEncode((String)key,"UTF-8")) + "=" +

common/src/main/java/json/org/json/JSONArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ public boolean isNull(int index) {
324324
*/
325325
public String join(String separator) throws JSONException {
326326
int len = length();
327-
StringBuffer sb = new StringBuffer();
327+
StringBuilder sb = new StringBuilder();
328328

329329
for (int i = 0; i < len; i += 1) {
330330
if (i > 0) {
@@ -820,7 +820,7 @@ String toString(int indentFactor, int indent) throws JSONException {
820820
return "[]";
821821
}
822822
int i;
823-
StringBuffer sb = new StringBuffer("[");
823+
StringBuilder sb = new StringBuilder("[");
824824
if (len == 1) {
825825
sb.append(JSONObject.valueToString(this.myArrayList.get(0),
826826
indentFactor, indent));

common/src/main/java/json/org/json/JSONObject.java

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,7 @@ public String toString() {
130130
* The hash map where the JSONObject's properties are kept.
131131
*/
132132
private HashMap<String, Object> myHashMap;
133-
private ArrayList<String> nameIndexList;
134-
135-
133+
private ArrayList<String> nameIndexList;
136134

137135
/**
138136
* It is sometimes more convenient and less ambiguous to have a
@@ -148,7 +146,7 @@ public String toString() {
148146
*/
149147
public JSONObject() {
150148
this.myHashMap = new HashMap<>();
151-
this.nameIndexList = new ArrayList<>();
149+
this.nameIndexList = new ArrayList<>();
152150
}
153151

154152

@@ -238,9 +236,9 @@ public JSONObject(Map map) {
238236
this.myHashMap = (map == null) ?
239237
new HashMap<>() :
240238
new HashMap<>(map);
241-
this.nameIndexList = (map == null) ?
242-
new ArrayList<>():
243-
new ArrayList<>(map.keySet());
239+
this.nameIndexList = (map == null) ?
240+
new ArrayList<>():
241+
new ArrayList<>(map.keySet());
244242
}
245243

246244

@@ -533,7 +531,7 @@ public boolean isNull(String key) {
533531
* @return An iterator of the keys.
534532
*/
535533
public Iterator<String> keys() {
536-
return this.nameIndexList.iterator();
534+
return this.nameIndexList.iterator();
537535
}
538536

539537

@@ -552,7 +550,7 @@ public int length() {
552550
*/
553551
public void clear() {
554552
this.myHashMap.clear();
555-
this.nameIndexList.clear();
553+
this.nameIndexList.clear();
556554
}
557555

558556

@@ -950,7 +948,7 @@ public static String quote(String string) {
950948
char c = 0;
951949
int i;
952950
int len = string.length();
953-
StringBuffer sb = new StringBuffer(len + 4);
951+
StringBuilder sb = new StringBuilder(len + 4);
954952
String t;
955953

956954
sb.append('"');
@@ -1004,8 +1002,8 @@ public static String quote(String string) {
10041002
* or null if there was no value.
10051003
*/
10061004
public Object remove(String key) {
1007-
if (this.nameIndexList.contains(key))
1008-
this.nameIndexList.remove(key);
1005+
if (this.nameIndexList.contains(key))
1006+
this.nameIndexList.remove(key);
10091007
return this.myHashMap.remove(key);
10101008
}
10111009

@@ -1066,7 +1064,7 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
10661064
public String toString() {
10671065
try {
10681066
Iterator keys = keys();
1069-
StringBuffer sb = new StringBuffer("{");
1067+
StringBuilder sb = new StringBuilder("{");
10701068

10711069
while (keys.hasNext()) {
10721070
if (sb.length() > 1) {
@@ -1122,7 +1120,7 @@ String toString(int indentFactor, int indent) throws JSONException {
11221120
return "{}";
11231121
}
11241122
Iterator keys = keys();
1125-
StringBuffer sb = new StringBuffer("{");
1123+
StringBuilder sb = new StringBuilder("{");
11261124
int newindent = indent + indentFactor;
11271125
Object o;
11281126
if (n == 1) {

common/src/main/java/json/org/json/JSONTokener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public char nextClean() throws JSONException {
209209
*/
210210
public String nextString(char quote) throws JSONException {
211211
char c;
212-
StringBuffer sb = new StringBuffer();
212+
StringBuilder sb = new StringBuilder();
213213
for (;;) {
214214
c = next();
215215
switch (c) {
@@ -284,7 +284,7 @@ public String nextTo(char d) {
284284
*/
285285
public String nextTo(String delimiters) {
286286
char c;
287-
StringBuffer sb = new StringBuffer();
287+
StringBuilder sb = new StringBuilder();
288288
for (;;) {
289289
c = next();
290290
if (delimiters.indexOf(c) >= 0 || c == 0 ||
@@ -331,7 +331,7 @@ public Object nextValue() throws JSONException {
331331
* formatting character.
332332
*/
333333

334-
StringBuffer sb = new StringBuffer();
334+
StringBuilder sb = new StringBuilder();
335335
char b = c;
336336
while (c >= ' ' && ",:]}/\\\"[{;=#".indexOf(c) < 0) {
337337
sb.append(c);

java/src/main/java/com/genexus/internet/HttpRequestWeb.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.genexus.PrivateUtilities;
99
import com.genexus.WrapperUtils;
1010
import com.genexus.webpanels.HttpContextWeb;
11+
import org.apache.commons.io.IOUtils;
1112

1213
public class HttpRequestWeb extends HttpRequest
1314
{
@@ -62,8 +63,8 @@ public String getString()
6263
String requestEncoding = "UTF-8";
6364
if (httpContext.getRequest().getCharacterEncoding() != null && httpContext.getRequest().getCharacterEncoding().length() > 0)
6465
requestEncoding = httpContext.getRequest().getCharacterEncoding();
65-
66-
return new String(PrivateUtilities.readToByteArray(getInputStream()), requestEncoding);
66+
67+
return new String(IOUtils.toByteArray(getInputStream()), requestEncoding);
6768
}
6869
catch (IOException e)
6970
{

0 commit comments

Comments
 (0)