Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: phantomcircuit on February 14, 2011, 10:53:15 PM



Title: Patch For Minor issue
Post by: phantomcircuit on February 14, 2011, 10:53:15 PM
diff --git a/net.h b/net.h
index f070816..205991f 100644
--- a/net.h
+++ b/net.h
@@ -16,7 +16,7 @@ inline unsigned short GetDefaultPort() { return fTestNet ? htons(18333) : htons(
 static const unsigned int PUBLISH_HOPS = 5;
 enum
 {
-    NODE_NETWORK = (1 << 0),
+    NODE_NETWORK = 1,
 };


Title: Re: Patch For Minor issue
Post by: jgarzik on February 14, 2011, 11:24:07 PM
diff --git a/net.h b/net.h
index f070816..205991f 100644
--- a/net.h
+++ b/net.h
@@ -16,7 +16,7 @@ inline unsigned short GetDefaultPort() { return fTestNet ? htons(18333) : htons(
 static const unsigned int PUBLISH_HOPS = 5;
 enum
 {
-    NODE_NETWORK = (1 << 0),
+    NODE_NETWORK = 1,
 };


The code is correct as-is.   This is the normal way someone defines bitmap constants, and is found throughout the Linux kernel among other places.

In the future, you would probably see
Code:
enum {
     NODE_NETWORK      = (1 << 0),
     NODE_FOO          = (1 << 1),
     NODE_BAR          = (1 << 2),
};

etc.



Title: Re: Patch For Minor issue
Post by: xenon481 on February 14, 2011, 11:27:39 PM
Since it is an enum, there are no significant performance differences.

Additionally, any decent compiler (with optimizations turned on) would optimize both the edited and non-edited lines of code to be the exact same thing since they are all constants.


Title: Re: Patch For Minor issue
Post by: Gavin Andresen on February 15, 2011, 12:31:10 AM
I agree with jgarzik:  the do-nothing << 0 is basically a comment saying "this is a bit-field."