summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorattilamolnar <attilamolnar@hush.com>2013-04-14 18:27:08 +0200
committerattilamolnar <attilamolnar@hush.com>2013-04-14 18:27:08 +0200
commit0a9f710e25f22fa67276aa8d15a008a5341b0f2a (patch)
tree437241dde736bb30b4b10f601342c12de4ab154b /src
parent48f7fa6b11a0a6b1526c54914e60ddbe51ede8c4 (diff)
Simplify UID generation logic
This loop is not required because we already set current_uid[pos] to 'A' before recursing if current_uid[pos] is 9
Diffstat (limited to 'src')
-rw-r--r--src/server.cpp41
1 files changed, 18 insertions, 23 deletions
diff --git a/src/server.cpp b/src/server.cpp
index d4797dce6..c49e17b56 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -106,35 +106,30 @@ void UIDGenerator::IncrementUID(unsigned int pos)
* A again, in an iterative fashion.. so..
* AAA9 -> AABA, and so on. -- w00t
*/
- if ((pos == 3) && (current_uid[3] == '9'))
+
+ // If we hit Z, wrap around to 0.
+ if (current_uid[pos] == 'Z')
+ {
+ current_uid[pos] = '0';
+ }
+ else if (current_uid[pos] == '9')
{
- // At pos 3, if we hit '9', we've run out of available UIDs, and need to reset to AAA..AAA.
- for (int i = 3; i < UUID_LENGTH-1; i++)
+ /*
+ * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
+ * e.g. A9 -> BA -> BB ..
+ */
+ current_uid[pos] = 'A';
+ if (pos == 3)
{
- current_uid[i] = 'A';
+ // At pos 3, if we hit '9', we've run out of available UIDs, and reset to AAA..AAA.
+ return;
}
+ this->IncrementUID(pos - 1);
}
else
{
- // If we hit Z, wrap around to 0.
- if (current_uid[pos] == 'Z')
- {
- current_uid[pos] = '0';
- }
- else if (current_uid[pos] == '9')
- {
- /*
- * Or, if we hit 9, wrap around to pos = 'A' and (pos - 1)++,
- * e.g. A9 -> BA -> BB ..
- */
- current_uid[pos] = 'A';
- this->IncrementUID(pos - 1);
- }
- else
- {
- // Anything else, nobody gives a shit. Just increment.
- current_uid[pos]++;
- }
+ // Anything else, nobody gives a shit. Just increment.
+ current_uid[pos]++;
}
}