Source:
<code>public List<Contentlet> searchByIdentifier(String luceneQuery, int limit, int offset, String sortBy, User user, boolean respectFrontendRoles, int requiredPermission, boolean anyLanguage) throws DotDataException,DotSecurityException { PaginatedArrayList<Contentlet> contents = new PaginatedArrayList<Contentlet>(); PaginatedArrayList <ContentletSearch> list =(PaginatedArrayList)searchIndex(luceneQuery, limit, offset, sortBy, user, respectFrontendRoles); contents.setTotalResults(list.getTotalResults()); List<String> identifierList = new ArrayList<String>(); for(ContentletSearch conwrap: list){ String ident=conwrap.getIdentifier(); Identifier ii=APILocator.getIdentifierAPI().find(ident); if(ii!=null && UtilMethods.isSet(ii.getId())) identifierList.add(ident); } String[] identifiers=new String[identifierList.size()]; identifiers=identifierList.toArray(identifiers); List<Contentlet> contentlets = new ArrayList<Contentlet>(); if(anyLanguage){ for(String identifier : identifierList){ for(Language lang : APILocator.getLanguageAPI().getLanguages()){ try{ Contentlet languageContentlet = null; try{ languageContentlet = findContentletByIdentifier(identifier, false, lang.getId(), user, respectFrontendRoles); }catch (DotContentletStateException e) { Logger.debug(this,e.getMessage(),e); } if(languageContentlet != null && UtilMethods.isSet(languageContentlet.getInode())){ contentlets.add(languageContentlet); break; } }catch(DotContentletStateException se){ Logger.debug(this, se.getMessage()); } } } }else{ contentlets = findContentletsByIdentifiers(identifiers, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, respectFrontendRoles); } for (Contentlet contentlet : contentlets) { <START> if (identifierList.contains(contentlet.getIdentifier())) <END> contents.add(contentlet); } return contents; }</code><technical_language>identifierList is a List contains call method is O(N), change Log(N) replacing implementation Set, worthy if switch collection implementation is a good idea</technical_language>

Target:
public List<Contentlet> searchByIdentifier(String luceneQuery, int limit, int offset, String sortBy, User user, boolean respectFrontendRoles, int requiredPermission, boolean anyLanguage) throws DotDataException,DotSecurityException { PaginatedArrayList <ContentletSearch> list =(PaginatedArrayList)searchIndex(luceneQuery, limit, offset, sortBy, user, respectFrontendRoles); Set<String> identifierList = new HashSet<>(); for(ContentletSearch conwrap: list){ String ident=conwrap.getIdentifier(); Identifier ii=APILocator.getIdentifierAPI().find(ident); if(ii!=null && UtilMethods.isSet(ii.getId())) identifierList.add(ident); } String[] identifiers=new String[identifierList.size()]; identifiers=identifierList.toArray(identifiers); List<Contentlet> contentlets = new ArrayList<Contentlet>(); if(anyLanguage){ for(String identifier : identifierList){ for(Language lang : APILocator.getLanguageAPI().getLanguages()){ try{ Contentlet languageContentlet = null; try{ languageContentlet = findContentletByIdentifier(identifier, false, lang.getId(), user, respectFrontendRoles); }catch (DotContentletStateException e) { Logger.debug(this,e.getMessage(),e); } if(languageContentlet != null && UtilMethods.isSet(languageContentlet.getInode())){ contentlets.add(languageContentlet); break; } }catch(DotContentletStateException se){ Logger.debug(this, se.getMessage()); } } } }else{ contentlets = findContentletsByIdentifiers(identifiers, false, APILocator.getLanguageAPI().getDefaultLanguage().getId(), user, respectFrontendRoles); } return contentlets; }