Home page logo
/

nmap-dev logo Nmap Development mailing list archives

[PATCH] "Optimizations" using logical NOTs instead of ?:
From: "Kris Katterjohn" <kjak () ispwest com>
Date: Wed, 22 Feb 2006 15:00:04 -0800

This replaces ?:'s with logical NOTs. Not that the ?:'s were really slowing
anything down, but logical NOTs are very inexpensive and, on my box, decrease the
binary size by about 100 bytes compared to using ?:. But then again, it's not a
big deal.

Thanks,
Kris Katterjohn

--- nmap-4.01-orig/Target.cc    2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/Target.cc 2006-02-22 15:58:19.000000000 -0600
@@ -330,7 +330,7 @@ bool Target::nextHop(struct sockaddr_sto
      that information here.  directlyConnected() will abort if it hasn't
      been set yet.  */
 void Target::setDirectlyConnected(bool connected) {
-  directly_connected = connected? 1 : 0;
+  directly_connected = !!connected;
 }
 
 bool Target::directlyConnected() {

--- nmap-4.01-orig/idle_scan.cc 2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/idle_scan.cc      2006-02-22 15:58:31.000000000 -0600
@@ -389,7 +389,7 @@ void initialize_idleproxy(struct idle_pr
 /* Now for the pcap opening nonsense ... */
  /* Note that the snaplen is 152 = 64 byte max IPhdr + 24 byte max link_layer
   * header + 64 byte max TCP header. */
-  proxy->pd = my_pcap_open_live(proxy->host.deviceName(), 152,  (o.spoofsource)? 1 : 0, 50);
+  proxy->pd = my_pcap_open_live(proxy->host.deviceName(), 152, !!o.spoofsource, 50);
 
   p = strdup(proxy->host.targetipstr());
   q = strdup(inet_ntoa(proxy->host.v4source()));

--- nmap-4.01-orig/nmap.cc      2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/nmap.cc   2006-02-22 16:43:27.000000000 -0600
@@ -2261,6 +2261,6 @@ int fileexistsandisreadable(char *pathna
   /* We check this the easy way! */
   fp = fopen(pathname, "r");
   if (fp) fclose(fp);
-  return (fp == NULL)? 0 : 1;
+  return !!fp;
 }
 

--- nmap-4.01-orig/nmapfe/nmapfe_sig.c  2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/nmapfe/nmapfe_sig.c       2006-02-22 16:06:44.000000000 -0600
@@ -1221,7 +1221,7 @@ gboolean stop_scan()
 void on_verb_activate(GtkMenuItem *menuitem, gpointer user_data)
 {
   /* toggle verb */
-  verb = (verb) ? 0 : 1;
+  verb = !verb;
 
   display_nmap_command();
 }

--- nmap-4.01-orig/nsock/src/nsock_iod.c        2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/nsock/src/nsock_iod.c     2006-02-22 16:06:56.000000000 -0600
@@ -263,7 +263,7 @@ void *nsi_getud(nsock_iod nsockiod) {
 
   /* Returns 1 if an NSI is communicating via SSL, 0 otherwise */
 int nsi_checkssl(nsock_iod nsockiod) {
-  return ((msiod *)nsockiod)->ssl? 1 : 0;
+  return !!((msiod *)nsockiod)->ssl;
 }
 
 /* Returns the remote peer port (or -1 if unavailable).  Note the

--- nmap-4.01-orig/osscan.cc    2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/osscan.cc 2006-02-22 16:00:02.000000000 -0600
@@ -314,7 +314,7 @@ get_random_bytes(&sequence_base, sizeof(
 ossofttimeout = MAX(200000, target->to.timeout);
 oshardtimeout = MAX(500000, 5 * target->to.timeout);
 
- pd = my_pcap_open_live(target->deviceName(), /*650*/ 8192,  (o.spoofsource)? 1 : 0, (ossofttimeout + 500)/ 1000);
+ pd = my_pcap_open_live(target->deviceName(), /*650*/ 8192, !!o.spoofsource, (ossofttimeout + 500)/ 1000);
 
 if (o.debugging > 1)
    log_write(LOG_STDOUT, "Wait time is %dms\n", (ossofttimeout +500)/1000);
@@ -1250,7 +1250,7 @@ int AVal_match(struct AVal *reference, s
   }
   if (num_subtests) *num_subtests += subtests;
   if (num_subtests_succeeded) *num_subtests_succeeded += subtests_succeeded;
-  return (subtests == subtests_succeeded)? 1 : 0;
+  return subtests == subtests_succeeded;
 }
 
 

--- nmap-4.01-orig/output.cc    2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/output.cc 2006-02-22 15:59:32.000000000 -0600
@@ -1285,7 +1285,7 @@ void printosscanoutput(Target *currenths
 /* An auxillary function for printserviceinfooutput(). Returns
    non-zero if a and b are considered the same hostnames. */
 static int hostcmp(const char *a, const char *b) {
-  return strcasestr(a, b)? 1 : 0;
+  return !!strcasestr(a, b);
 }
 
 
--- nmap-4.01-orig/scan_engine.cc       2006-02-22 16:28:49.000000000 -0600
+++ nmap-4.01/scan_engine.cc    2006-02-22 15:59:41.000000000 -0600
@@ -3176,7 +3176,7 @@ static void begin_sniffer(UltraScanInfo 
   }
   filterlen = 0;
 
-  USI->pd = my_pcap_open_live(Targets[0]->deviceName(), 100,  (o.spoofsource)? 1 : 0, 2);
+  USI->pd = my_pcap_open_live(Targets[0]->deviceName(), 100, !!o.spoofsource, 2);
 
   if (USI->tcp_scan || USI->udp_scan) {
     if (doIndividual)




_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev


  By Date           By Thread  

Current thread:
  • [PATCH] "Optimizations" using logical NOTs instead of ?: Kris Katterjohn (Feb 22)
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]