Skip to content

Commit 1eb9660

Browse files
authored
Changes to improve performance in web events when a lot of data are i… (#836)
* Changes to improve performance in web events when a lot of data are in the page Issue: 107443 * Changes to improve performance in web events when a lot of data are in the page Issue: 107443
1 parent 39baed9 commit 1eb9660

File tree

6 files changed

+33
-34
lines changed

6 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
@@ -179,7 +179,7 @@ public Object initialValue()
179179

180180
public static String removeAllQuotes(String fileName)
181181
{
182-
StringBuffer out = new StringBuffer();
182+
StringBuilder out = new StringBuilder();
183183
int len = fileName.length();
184184
for (int i = 0; i < len; i++)
185185
if (fileName.charAt(i) != '"')
@@ -1023,7 +1023,7 @@ public static String strReplace(String s, String subString, String replacement)
10231023
return s;
10241024

10251025
int index, start, subLength;
1026-
StringBuffer buf = new StringBuffer();
1026+
StringBuilder buf = new StringBuilder();
10271027
subLength = subString.length();
10281028

10291029
for (start = 0, index = s.indexOf(subString, start); index >= 0; start = index + subLength, index = s.indexOf(subString, start))
@@ -1080,7 +1080,7 @@ public static String replicate (char character, int size)
10801080
if (size <= 0)
10811081
return "";
10821082

1083-
StringBuffer ret = new StringBuffer(size);
1083+
StringBuilder ret = new StringBuilder(size);
10841084

10851085
for (int i = 0; i < size; i++)
10861086
{
@@ -1095,7 +1095,7 @@ public static String replicate (String character, int size, int a)
10951095
if (size <= 0)
10961096
return "";
10971097

1098-
StringBuffer ret = new StringBuffer(size);
1098+
StringBuilder ret = new StringBuilder(size);
10991099

11001100
for (int i = 0; i < size; i++)
11011101
{
@@ -1218,7 +1218,7 @@ public static long lval(String text)
12181218
}
12191219
catch (Exception e)
12201220
{
1221-
StringBuffer out = new StringBuffer();
1221+
StringBuilder out = new StringBuilder();
12221222

12231223
boolean first = true;
12241224
int len = text.length();
@@ -1282,8 +1282,8 @@ public static BigDecimal decimalVal(String text, String sDSep)
12821282
return BigDecimal.ZERO;
12831283
}
12841284

1285-
private static StringBuffer extractNumericStringValue(String text, String sDSep) {
1286-
StringBuffer out = new StringBuffer();
1285+
private static StringBuilder extractNumericStringValue(String text, String sDSep) {
1286+
StringBuilder out = new StringBuilder();
12871287

12881288
char dSep = (sDSep.length() > 0) ? sDSep.charAt(0) : '.';
12891289
boolean point = false;
@@ -1861,7 +1861,7 @@ protected static boolean in(String text , char c)
18611861

18621862
public static String getTimeFormat(String time)
18631863
{
1864-
StringBuffer ret = new StringBuffer(time);
1864+
StringBuilder ret = new StringBuilder(time);
18651865
char hora;
18661866
boolean app = false;
18671867
char append = ' ';
@@ -2337,7 +2337,7 @@ public static boolean contains(Object []arr, Object item)
23372337
public static String format(String value, String v1, String v2, String v3, String v4, String v5, String v6, String v7, String v8, String v9)
23382338
{
23392339
String[] vs = {v1, v2, v3, v4, v5, v6, v7, v8, v9};
2340-
StringBuffer stringBuilder = new StringBuffer();
2340+
StringBuilder stringBuilder = new StringBuilder();
23412341
int valueLength = value.length();
23422342
if (value != null && !value.equals(""))
23432343
{
@@ -2560,7 +2560,7 @@ public static String strUnexponentString(String num)
25602560
int point = num.indexOf('.');
25612561
int scale = num.length() - (point == -1 ? num.length () : point + 1) - scaleAdj;
25622562

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

25652565
// correct for negative scale as per BigDecimal javadoc
25662566
for(; scale<0; scale++)
@@ -2907,7 +2907,7 @@ public static String strori(double val, int digits, int decimals)
29072907
if (decimals < 0) decimals = 0;
29082908
if (digits < 0) digits = 0;
29092909

2910-
StringBuffer b = new StringBuffer();
2910+
StringBuilder b = new StringBuilder();
29112911
boolean hasSign = (val < 0);
29122912

29132913
if (hasSign)
@@ -3116,7 +3116,7 @@ public static String addLastPathSeparator(String dir) {
31163116
}
31173117

31183118
public static String quoteString(String in, boolean entities8bit, boolean encodeQuotes) {
3119-
StringBuffer out = new StringBuffer();
3119+
StringBuilder out = new StringBuilder();
31203120
for (int i = 0; i < in.length(); i++)
31213121
{
31223122
char currentChar = in.charAt(i);
@@ -3383,7 +3383,7 @@ public final static String hashtable2query(Hashtable hashtable)
33833383
if (hashtable == null)
33843384
return null;
33853385

3386-
StringBuffer qbuf = new StringBuffer();
3386+
StringBuilder qbuf = new StringBuilder();
33873387
for (Enumeration en = hashtable.keys(); en.hasMoreElements();) {
33883388
Object key = en.nextElement();
33893389
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

@@ -945,7 +943,7 @@ public static String quote(String string) {
945943
char c = 0;
946944
int i;
947945
int len = string.length();
948-
StringBuffer sb = new StringBuffer(len + 4);
946+
StringBuilder sb = new StringBuilder(len + 4);
949947
String t;
950948

951949
sb.append('"');
@@ -993,8 +991,8 @@ public static String quote(String string) {
993991
* or null if there was no value.
994992
*/
995993
public Object remove(String key) {
996-
if (this.nameIndexList.contains(key))
997-
this.nameIndexList.remove(key);
994+
if (this.nameIndexList.contains(key))
995+
this.nameIndexList.remove(key);
998996
return this.myHashMap.remove(key);
999997
}
1000998

@@ -1055,7 +1053,7 @@ public JSONArray toJSONArray(JSONArray names) throws JSONException {
10551053
public String toString() {
10561054
try {
10571055
Iterator keys = keys();
1058-
StringBuffer sb = new StringBuffer("{");
1056+
StringBuilder sb = new StringBuilder("{");
10591057

10601058
while (keys.hasNext()) {
10611059
if (sb.length() > 1) {
@@ -1111,7 +1109,7 @@ String toString(int indentFactor, int indent) throws JSONException {
11111109
return "{}";
11121110
}
11131111
Iterator keys = keys();
1114-
StringBuffer sb = new StringBuffer("{");
1112+
StringBuilder sb = new StringBuilder("{");
11151113
int newindent = indent + indentFactor;
11161114
Object o;
11171115
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);

gxweb/src/main/java/com/genexus/internet/HttpAjaxContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ public void ajax_rsp_assign_sdt_attri( String CmpContext, boolean IsMasterPage,
868868
{
869869
try {
870870
JSONObject obj = getGxObject(AttValues, CmpContext, IsMasterPage);
871-
if (obj != null && (dynAjaxEventContext.isParmModified(AttName, SdtObj) || !isUndefinedOutParam( AttName, SdtObj)))
871+
if (obj != null && (!isUndefinedOutParam( AttName, SdtObj) || dynAjaxEventContext.isParmModified(AttName, SdtObj)))
872872
{
873873
if (SdtObj instanceof IGxJSONAble)
874874
obj.put(AttName, ((IGxJSONAble)SdtObj).GetJSONObject());

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

Lines changed: 2 additions & 1 deletion
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
{
@@ -63,7 +64,7 @@ public String getString()
6364
if (httpContext.getRequest().getCharacterEncoding() != null && httpContext.getRequest().getCharacterEncoding().length() > 0)
6465
requestEncoding = httpContext.getRequest().getCharacterEncoding();
6566

66-
return new String(PrivateUtilities.readToByteArray(is), requestEncoding);
67+
return new String(IOUtils.toByteArray(is), requestEncoding);
6768
}
6869
catch (IOException e)
6970
{

0 commit comments

Comments
 (0)