Return-Path: Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: (qmail 60225 invoked from network); 16 Apr 2009 13:54:37 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Apr 2009 13:54:37 -0000 Received: (qmail 87722 invoked by uid 500); 16 Apr 2009 13:54:36 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 87627 invoked by uid 500); 16 Apr 2009 13:54:36 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 87483 invoked by uid 99); 16 Apr 2009 13:54:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Apr 2009 13:54:35 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.140] (HELO brutus.apache.org) (140.211.11.140) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Apr 2009 13:54:35 +0000 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id 165E6234C045 for ; Thu, 16 Apr 2009 06:54:15 -0700 (PDT) Message-ID: <588943973.1239890055090.JavaMail.jira@brutus> Date: Thu, 16 Apr 2009 06:54:15 -0700 (PDT) From: "Bruce Collie (JIRA)" To: issues@commons.apache.org Subject: [jira] Commented: (VALIDATOR-266) DomainValidator uses an O(n) method where an O(1) would be more appropriate In-Reply-To: <63617539.1213702065226.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/VALIDATOR-266?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12699706#action_12699706 ] Bruce Collie commented on VALIDATOR-266: ---------------------------------------- A better solution would be to sort the arrays within a static block e.g. static { Arrays.sort(INFRASTRUCTURE_TLDS); Arrays.sort(COUNTRY_CODE_TLDS); Arrays.sort(GENERIC_TLDS); Arrays.sort(COUNTRY_CODE_TLDS); } Then use Arrays.binarySearch in the various isvalidXXX() calls e.g. public boolean isValidInfrastructureTld(String iTld) { return Arrays.binarySearch(INFRASTRUCTURE_TLDS,chompLeadingDot(iTld.toLowerCase()))>=0; } That way the lists are obsolete and you save a little memory at the same time > DomainValidator uses an O(n) method where an O(1) would be more appropriate > --------------------------------------------------------------------------- > > Key: VALIDATOR-266 > URL: https://issues.apache.org/jira/browse/VALIDATOR-266 > Project: Commons Validator > Issue Type: Bug > Components: Routines > Affects Versions: 1.4 > Reporter: Chris Wareham > Priority: Minor > > The class org.apache.commons.validator.routines.DomainValidator contains several hard coded arrays of TLD names. Quite apart from whether these should be in a properties file rather than the source file itself, they are then used to populate List instances via Arrays.asList() and the List.contains() method used when validating a TLD. This is almost inevitably an O(n) operation on each list, and could be improved by populating a single HashSet which would provide O(1) performance. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.