Skip to content

Commit e3ba1a9

Browse files
Micro optims and no ; after //
1 parent 14d4e23 commit e3ba1a9

File tree

8 files changed

+27
-54
lines changed

8 files changed

+27
-54
lines changed

SerialX-core/src/main/java/org/ugp/serialx/converters/DataConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ default CharSequence toString(ParserRegistry myHomeRegistry, Object obj, Object.
4343
* @param obj | Object to convert into string!
4444
* @param args | Some additional args. This can be anything and it demands on implementation of DataConverter. Default SerialX API implementation will provide some flags about formating (2 ints)!
4545
*
46-
* @return The source appendable after stringified object (obj) was appropriately appended into it.
46+
* @return The source appendable after stringified object (obj) was appropriately appended into it. Alternatively you can return null to signify error or that everything necessary was already appended and no further chars should be appended immediately after this obj's stringification.
4747
* Return {@link DataParser#CONTINUE} to tell that this converter is not suitable for converting this object! You most likely want to do this when obtained obj is not suitable instance!
4848
*
4949
* @throws IOException When appending into source throws it...

SerialX-core/src/main/java/org/ugp/serialx/converters/DataParser.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public static class ParserRegistry extends Registry<DataParser> implements DataP
8282
private static final long serialVersionUID = -2598324826689380752L;
8383

8484
protected DataParser[] parsingCache;
85-
protected DataParser[] convertingCache;
85+
protected DataConverter[] convertingCache;
8686

8787
/**
8888
* Constructs an {@link ParserRegistry} with the specified initial capacity.
@@ -185,7 +185,7 @@ public CharSequence toString(Object obj, Object... args)
185185
* @param obj | Object to convert into string!
186186
* @param args | Additional arguments that will be obtained in {@link DataParser#toString(String, Object...)}!
187187
*
188-
* @return The source appendable after stringified object (obj) was appropriately appended into it.
188+
* @return The source appendable after stringified object (obj) was appropriately appended into it. Alternatively you can return null to signify error or that everything necessary was already appended and no further chars should be appended immediately after this obj's stringification.
189189
* Return {@link DataParser#CONTINUE} to tell that this converter is not suitable for converting this object! You most likely want to do this when obtained obj is not suitable instance!
190190
*
191191
* @throws IOException When appending into source throws it...
@@ -196,8 +196,8 @@ public Appendable toString(Appendable source, Object obj, Object... args) throws
196196
{
197197
Appendable str;
198198
if (convertingCache != null)
199-
for (DataParser parser : convertingCache)
200-
if (parser != null && (str = ((DataConverter) parser).toString(source, this, obj, args)) != CONTINUE)
199+
for (DataConverter parser : convertingCache)
200+
if (parser != null && (str = parser.toString(source, this, obj, args)) != CONTINUE)
201201
return str;
202202

203203
for (int i = 0, size = size(); i < size; i++)
@@ -206,7 +206,7 @@ public Appendable toString(Appendable source, Object obj, Object... args) throws
206206
if (parser instanceof DataConverter && (str = ((DataConverter) parser).toString(source, this, obj, args)) != CONTINUE)
207207
{
208208
if (convertingCache != null && i < convertingCache.length)
209-
convertingCache[i] = parser;
209+
convertingCache[i] = (DataConverter) parser;
210210
return str;
211211
}
212212
}
@@ -326,9 +326,9 @@ public int[] preCache(Class<? extends DataParser> classOfParserToPrecache)
326326
ret[0] = i;
327327
}
328328

329-
if (i < convertingCache.length)
329+
if (i < convertingCache.length && parser instanceof DataConverter)
330330
{
331-
convertingCache[i] = parser;
331+
convertingCache[i] = (DataConverter) parser;
332332
ret[1] = i;
333333
}
334334

@@ -346,7 +346,7 @@ public int[] preCache(Class<? extends DataParser> classOfParserToPrecache)
346346
public void resetCache()
347347
{
348348
int size = size();
349-
resetCache(new DataParser[size], new DataParser[size]);
349+
resetCache(new DataParser[size], new DataConverter[size]);
350350
}
351351

352352
/**
@@ -357,7 +357,7 @@ public void resetCache()
357357
*
358358
* @since 1.3.5
359359
*/
360-
public void resetCache(DataParser[] parsingCache, DataParser[] convertingCache)
360+
public void resetCache(DataParser[] parsingCache, DataConverter[] convertingCache)
361361
{
362362
if (parsingCache != null)
363363
this.parsingCache = parsingCache;
@@ -390,7 +390,7 @@ public DataParser[] getParsingCache()
390390
*
391391
* @since 1.3.5
392392
*/
393-
public DataParser[] getConverterCache()
393+
public DataConverter[] getConverterCache()
394394
{
395395
return convertingCache;
396396
}

SerialX-core/src/main/java/org/ugp/serialx/converters/ProtocolConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public Appendable toString(Appendable source, ParserRegistry myHomeRegistry, Obj
179179
* @param preferedProtocol | Protocol to use preferably.
180180
* @param args | Some additional args. This can be anything and it demands on implementation of DataConverter. Default SerialX API implementation will provide some flags about formating (2 ints)!
181181
*
182-
* @return The source appendable after stringified object (obj) was appropriately appended into it.
182+
* @return The source appendable after stringified object (obj) was appropriately appended into it. Alternatively you can return null to signify error or that everything necessary was already appended and no further chars should be appended immediately after this obj's stringification.
183183
* Return {@link DataParser#CONTINUE} to tell that this converter is not suitable for converting this object! You most likely want to do this when obtained obj is not suitable instance!
184184
*
185185
* @since 1.3.5

SerialX-core/src/main/java/org/ugp/serialx/converters/StringConverter.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public Appendable toString(Appendable source, ParserRegistry myHomeRegistry, Obj
7878
str = str.substring(2, str.length()-1);
7979
if (str.contains("::") && indexOfNotInObj(str, ' ') > -1)
8080
return source.append('{').append(str).append('}');
81+
82+
if (indexOfNotInObj(str, "//") != -1)
83+
{
84+
source.append(str);
85+
return null; // No append ; when ends with //
86+
}
8187
return source.append(str);
8288
}
8389

SerialX-devtools/src/main/java/org/ugp/serialx/devtools/DebugParserRegistry.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ public Appendable toString(Appendable source, Object obj, Object... args) throws
6363
if (convertingCache != null)
6464
for (int i = 0; i < convertingCache.length; i++)
6565
{
66-
DataParser parser = convertingCache[i];
67-
if (parser != null)
66+
DataConverter converter = convertingCache[i];
67+
if (converter != null)
6868
{
6969
double t0 = System.nanoTime();
70-
str = (CharSequence) ((DataConverter) parser).toString(new StringBuilder(), this, obj, args);
70+
str = (CharSequence) converter.toString(new StringBuilder(), this, obj, args);
7171
double t = System.nanoTime();
7272
if (str != SerializationDebugger.CONTINUE)
7373
{
74-
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms (from cache)\n>>\t" + SerializationDebugger.toStringAndCls(obj) + "\t -->\t\"" + str + "\"");
74+
iterationStackTrace.put(iterationIndex, "[" + i + "] " + converter + " " + (t-t0)/1000000 + "ms (from cache)\n>>\t" + SerializationDebugger.toStringAndCls(obj) + "\t -->\t\"" + str + "\"");
7575
return source.append(str);
7676
}
7777
}
@@ -88,7 +88,7 @@ public Appendable toString(Appendable source, Object obj, Object... args) throws
8888
if(str != SerializationDebugger.CONTINUE)
8989
{
9090
if (convertingCache != null && i < convertingCache.length)
91-
convertingCache[i] = parser;
91+
convertingCache[i] = (DataConverter) parser;
9292
iterationStackTrace.put(iterationIndex, "[" + i + "] " + parser + " " + (t-t0)/1000000 + "ms\n>>\t" + SerializationDebugger.toStringAndCls(obj) + "\t -->\t\"" + str + "\"");
9393
return source.append(str);
9494
}

SerialX-json/src/main/java/org/ugp/serialx/json/JsonSerializer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ protected Appendable appandVar(Appendable source, ParserRegistry parsersToUse, E
204204
{
205205
if (format != 0)
206206
source.append(multilpy('\t', tabs));
207-
parsersToUse.toString(source, varToSerialize, args);
208-
if (isLast)
207+
if (parsersToUse.toString(source, varToSerialize, args) == null || isLast)
209208
return source;
210209
return source.append(',');
211210
}
@@ -215,8 +214,7 @@ protected Appendable appandVal(Appendable source, ParserRegistry parsersToUse, O
215214
{
216215
if (format != 0)
217216
source.append(multilpy('\t', tabs));
218-
parsersToUse.toString(source, objToSerialize, args);
219-
if (isLast /*|| serializedVal != null && indexOfNotInObj(serializedVal, "//") != -1*/)
217+
if (parsersToUse.toString(source, objToSerialize, args) == null || isLast)
220218
return source;
221219
return source.append(',');
222220
}

SerialX-juss/src/main/java/org/ugp/serialx/juss/JussSerializer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,7 @@ protected Appendable appandVar(Appendable source, ParserRegistry parsersToUse, E
401401
{
402402
if (format != 0)
403403
source.append(multilpy('\t', tabs));
404-
parsersToUse.toString(source, varToSerialize, args);
405-
if (isLast)
404+
if (parsersToUse.toString(source, varToSerialize, args) == null || isLast)
406405
return source;
407406
return source.append(';');
408407
}
@@ -416,8 +415,7 @@ protected Appendable appandVal(Appendable source, ParserRegistry parsersToUse, O
416415
{
417416
if (format != 0)
418417
source.append(multilpy('\t', tabs));
419-
parsersToUse.toString(source, objToSerialize, args);
420-
if (isLast /*|| serializedVal != null && indexOfNotInObj(serializedVal, "//") != -1*/)
418+
if (parsersToUse.toString(source, objToSerialize, args) == null || isLast)
421419
return source;
422420
return source.append(';');
423421
}

SerialX-juss/src/main/java/org/ugp/serialx/juss/converters/ObjectConverter.java

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,14 @@
33
import static org.ugp.serialx.Utils.indexOfNotInObj;
44

55
import java.io.IOException;
6-
import java.io.Serializable;
76
import java.io.StringReader;
87
import java.util.Arrays;
9-
import java.util.Base64;
108

119
import org.ugp.serialx.GenericScope;
1210
import org.ugp.serialx.LogProvider;
1311
import org.ugp.serialx.Scope;
1412
import org.ugp.serialx.Serializer;
15-
import org.ugp.serialx.converters.DataParser;
1613
import org.ugp.serialx.converters.ProtocolConverter;
17-
import org.ugp.serialx.converters.SerializableBase64Converter;
18-
import org.ugp.serialx.converters.DataParser.ParserRegistry;
1914
import org.ugp.serialx.converters.imports.ImportsProvider;
2015
import org.ugp.serialx.juss.JussSerializer;
2116
import org.ugp.serialx.protocols.SerializationProtocol;
@@ -64,18 +59,6 @@ <td>new Scope( ... )</td>
6459
*/
6560
public class ObjectConverter extends ProtocolConverter
6661
{
67-
/**
68-
* Set this on true to force program to use {@link Base64} serialization on {@link Serializable} objects.
69-
* Doing this might result into some form of encryption but its less flexible and tends to be slower than SerialX {@link SerializationProtocol} system!
70-
* In some cases, java Serialization can be more effective than protocols sometimes not! You should try which gives you the best result, then you can also deactivate certain protocols that are less effective than Java serialization.
71-
* For example for long strings, classic Java serialization is better than protocol, it will take less memory storage space, but performance is almost always far slower!<br>
72-
* Note: Whole concept of SerialX API is about avoiding classic Java serialization from many reasons so you most likely want this on true! Also protocol will be almost certainly faster classic serialization!<br>
73-
* Note: This will only work when this converter is registered in {@link ParserRegistry} together with {@link SerializableBase64Converter}!
74-
*
75-
* @since 1.0.0 (moved to {@link SerializableBase64Converter} since 1.3.0 and since 1.3.5 into {@link ObjectConverter})
76-
*/
77-
protected boolean useBase64IfCan = false;
78-
7962
@SuppressWarnings("unchecked")
8063
@Override
8164
public Object parse(ParserRegistry myHomeRegistry, String str, Object... compilerArgs)
@@ -142,18 +125,6 @@ public Appendable toString(Appendable source, ParserRegistry myHomeRegistry, Obj
142125
return toString(source, myHomeRegistry, obj, null, args);
143126
}
144127

145-
/**
146-
* @param source | Source to append the properly stringified object (obj) into. Should be treated as only and only {@link Appendable}, no casting!
147-
* @param myHomeRegistry | Registry where this parser is registered provided by {@link ParserRegistry#parse(String, boolean, Class, Object...)} otherwise it demands on implementation (it should not be null)!
148-
* @param obj | Object to convert into string!
149-
* @param preferedProtocol | Protocol to use preferably.
150-
* @param args | Some additional args. This can be anything and it demands on implementation of DataConverter. Default SerialX API implementation will provide some flags about formating (2 ints)!
151-
*
152-
* @return The source appendable after stringified object (obj) was appropriately appended into it.
153-
* Return {@link DataParser#CONTINUE} to tell that this converter is not suitable for converting this object! You most likely want to do this when obtained obj is not suitable instance!
154-
*
155-
* @since 1.3.5
156-
*/
157128
@SuppressWarnings("unchecked")
158129
public Appendable toString(Appendable source, ParserRegistry myHomeRegistry, Object obj, SerializationProtocol<Object> preferedProtocol, Object... args)
159130
{

0 commit comments

Comments
 (0)