[tor-bugs] #17824 [metrics-lib]: switch on string instead of many if-else with String comparison

Tor Bug Tracker & Wiki blackhole at torproject.org
Fri Dec 11 20:27:55 UTC 2015


#17824: switch on string instead of many if-else with String comparison
-----------------------------+---------------------
     Reporter:  iwakeh       |      Owner:  karsten
         Type:  enhancement  |     Status:  new
     Priority:  Low          |  Milestone:
    Component:  metrics-lib  |    Version:
     Severity:  Minor        |   Keywords:
Actual Points:               |  Parent ID:  #17822
       Points:               |    Sponsor:
-----------------------------+---------------------
 example from BridgeNetworkStatusImpl (there are many more and longer
 ones):

 {{{
   switch(keyword){
       case "published":
         this.parsePublishedLine(line, parts);
       case "flag-thresholds":
         this.parseFlagThresholdsLine(line, parts);
    }
    if (this.failUnrecognizedDescriptorLines) {
       throw new DescriptorParseException("Unrecognized line '" + line
             + "' in bridge network status.");
    } else {
       if (this.unrecognizedLines == null) {
          this.unrecognizedLines = new ArrayList<String>();
      }
 ...
 }}}

 instead of

 {{{
   if (keyword.equals("published")) {
         this.parsePublishedLine(line, parts);
       } else if (keyword.equals("flag-thresholds")) {
         this.parseFlagThresholdsLine(line, parts);
       } else if (this.failUnrecognizedDescriptorLines) {
         throw new DescriptorParseException("Unrecognized line '" + line
             + "' in bridge network status.");
       } else {
         if (this.unrecognizedLines == null) {
           this.unrecognizedLines = new ArrayList<String>();
         }

 }}}

--
Ticket URL: <https://trac.torproject.org/projects/tor/ticket/17824>
Tor Bug Tracker & Wiki <https://trac.torproject.org/>
The Tor Project: anonymity online


More information about the tor-bugs mailing list