Merge pull request #3657 from TheRealHaui/small-minor-performance-improvements

Using `isEmpty()` instead of testing size/length.
This commit is contained in:
Simone Bordet 2019-05-15 21:29:07 +02:00 committed by GitHub
commit f0e4102896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 18 additions and 18 deletions

View File

@ -119,7 +119,7 @@ public class JettyJspServlet extends JspServlet
*/
private String addPaths(String servletPath, String pathInfo)
{
if (servletPath.length()==0)
if (servletPath.isEmpty())
return pathInfo;
if (pathInfo==null)

View File

@ -79,7 +79,7 @@ public class ManyHandlers
ServletException
{
Map<String, String[]> params = request.getParameterMap();
if (params.size() > 0)
if (!params.isEmpty())
{
response.setContentType("text/plain");
response.getWriter().println(JSON.toString(params));

View File

@ -47,7 +47,7 @@ public class WebSocketCdiListener extends AbstractContainerListener
ScopedInstance sbean = new ScopedInstance();
Set<Bean<?>> beans = bm.getBeans(clazz,AnyLiteral.INSTANCE);
if (beans.size() > 0)
if (!beans.isEmpty())
{
sbean.bean = beans.iterator().next();
sbean.creationalContext = bm.createCreationalContext(sbean.bean);

View File

@ -87,7 +87,7 @@ public class HttpChannelOverFCGI extends HttpChannel
public void onRequest()
{
String uri = path;
if (query != null && query.length() > 0)
if (query != null && !query.isEmpty())
uri += "?" + query;
// TODO https?
onRequest(new MetaData.Request(method, HttpScheme.HTTP.asString(), hostPort, uri, HttpVersion.fromString(version), fields,Long.MIN_VALUE));

View File

@ -100,7 +100,7 @@ public class HttpField
{
if (search==null)
return _value==null;
if (search.length()==0)
if (search.isEmpty())
return false;
if (_value==null)
return false;

View File

@ -1013,7 +1013,7 @@ public class HttpParser
else
{
List<String> values = new QuotedCSV(_valueString).getValues();
if (values.size()>0 && HttpHeaderValue.CHUNKED.is(values.get(values.size()-1)))
if (!values.isEmpty() && HttpHeaderValue.CHUNKED.is(values.get(values.size()-1)))
{
_endOfContent=EndOfContent.CHUNKED_CONTENT;
_contentLength=-1;

View File

@ -554,7 +554,7 @@ public class HttpURI
public String getHost()
{
// Return null for empty host to retain compatibility with java.net.URI
if (_host!=null && _host.length()==0)
if (_host!=null && _host.isEmpty())
return null;
return _host;
}
@ -599,7 +599,7 @@ public class HttpURI
/* ------------------------------------------------------------ */
public boolean hasQuery()
{
return _query!=null && _query.length()>0;
return _query!=null && !_query.isEmpty();
}
/* ------------------------------------------------------------ */
@ -653,7 +653,7 @@ public class HttpURI
/* ------------------------------------------------------------ */
public boolean isAbsolute()
{
return _scheme!=null && _scheme.length()>0;
return _scheme!=null && !_scheme.isEmpty();
}
/* ------------------------------------------------------------ */

View File

@ -223,7 +223,7 @@ public class MimeTypes
.forEach(x->
__dftMimeMap.put(StringUtil.asciiToLowerCase(x), normalizeMimeType(props.getProperty(x))));
if (__dftMimeMap.size()==0)
if (__dftMimeMap.isEmpty())
{
LOG.warn("Empty mime types at {}", resourceName);
}
@ -268,7 +268,7 @@ public class MimeTypes
__inferredEncodings.put(t, props.getProperty(t));
});
if (__inferredEncodings.size()==0)
if (__inferredEncodings.isEmpty())
{
LOG.warn("Empty encodings at {}", resourceName);
}

View File

@ -107,7 +107,7 @@ public class MultiPartFormInputStream
// We will either be writing to a file, if it has a filename on the content-disposition
// and otherwise a byte-array-input-stream, OR if we exceed the getFileSizeThreshold, we
// will need to change to write to a file.
if (isWriteFilesWithFilenames() && _filename != null && _filename.trim().length() > 0)
if (isWriteFilesWithFilenames() && _filename != null && !_filename.trim().isEmpty())
{
createFile();
}
@ -365,7 +365,7 @@ public class MultiPartFormInputStream
Collection<List<Part>> values = _parts.values();
for (List<Part> partList : values)
{
if (partList.size() != 0)
if (!partList.isEmpty())
return false;
}

View File

@ -294,7 +294,7 @@ public class PathMap<O> extends HashMap<String,O>
if (path==null)
return entries;
if (path.length()==0)
if (path.isEmpty())
return _defaultSingletonList;
// try exact match
@ -417,7 +417,7 @@ public class PathMap<O> extends HashMap<String,O>
*/
public static boolean match(String pathSpec, String path, boolean noDefault)
{
if (pathSpec.length()==0)
if (pathSpec.isEmpty())
return "/".equals(path);
char c = pathSpec.charAt(0);

View File

@ -46,10 +46,10 @@ public class CookieDump extends HttpServlet
String value = request.getParameter("Value");
String age = request.getParameter("Age");
if (name!=null && name.length()>0)
if (name!=null && !name.isEmpty())
{
Cookie cookie = new Cookie(name,value);
if (age!=null && age.length()>0)
if (age!=null && !age.isEmpty())
cookie.setMaxAge(Integer.parseInt(age));
response.addCookie(cookie);
}

View File

@ -91,7 +91,7 @@ public class SessionDump extends HttpServlet
{
if (action.equals("Invalidate"))
session.invalidate();
else if (action.equals("Set") && name!=null && name.length()>0)
else if (action.equals("Set") && name!=null && !name.isEmpty())
session.setAttribute(name,value);
else if (action.equals("Remove"))
session.removeAttribute(name);