Skip to content

Commit c3d75b3

Browse files
committed
Merge pull request #229 from datastax/305
305 - Table-based conversion of UUIDs to and from strings
2 parents 4169398 + 0ff239e commit c3d75b3

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

CMakeLists.txt

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -442,22 +442,9 @@ elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
442442
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
443443
# Clang/Intel specific compiler options
444444
# I disabled long-long warning because boost generates about 50 such warnings
445-
set(WARNING_COMPILER_FLAGS "-Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter -Wno-variadic-macros -Wno-zero-length-array")
446-
447-
# Detect if this is Apple's clang
448-
execute_process(COMMAND ${CMAKE_CXX_COMPILER} -v ERROR_VARIABLE CASS_CLANG_VERSION_INFO)
449-
if (CASS_CLANG_VERSION_INFO MATCHES "^Apple LLVM")
450-
set(CASS_IS_APPLE_CLANG 1)
451-
else()
452-
set(CASS_IS_APPLE_CLANG 0)
453-
endif()
454-
455-
if(NOT CASS_IS_APPLE_CLANG AND
456-
(${CMAKE_CXX_COMPILER_VERSION} VERSION_EQUAL "3.6" OR
457-
${CMAKE_CXX_COMPILER_VERSION} VERSION_GREATER "3.6")
458-
)
459-
set(WARNING_COMPILER_FLAGS "${WARNING_COMPILER_FLAGS} -Wno-unused-local-typedef ")
460-
endif()
445+
set(WARNING_COMPILER_FLAGS "-Wall -pedantic -Wextra -Wno-long-long -Wno-unused-parameter")
446+
set(WARNING_COMPILER_FLAGS "${WARNING_COMPILER_FLAGS} -Wno-variadic-macros -Wno-zero-length-array")
447+
set(WARNING_COMPILER_FLAGS "${WARNING_COMPILER_FLAGS} -Wno-unused-local-typedef -Wno-unknown-warning-option")
461448

462449
# OpenSSL is deprecated on later versions of Mac OS X. The long-term solution
463450
# is to provide a CommonCryto implementation.

packaging/homebrew/cassandra-cpp-driver.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33
class CassandraCppDriver < Formula
44
homepage "http://datastax.github.io/cpp-driver/"
5-
url "https://github.com/datastax/cpp-driver/archive/2.0.1.tar.gz"
6-
sha1 "67a5b4e52ec421407c34ba7df109faeeaf4ef6dd"
7-
version "2.0.1"
5+
url "https://github.com/datastax/cpp-driver/archive/2.2.0-beta1.tar.gz"
6+
sha1 "6159f1a5e31a044fb70567f849286572afa57174"
7+
version "2.2.0-beta1"
88

9-
head "git://github.com:datastax/cpp-driver.git", :branch => "2.0"
9+
head "git://github.com:datastax/cpp-driver.git", :branch => "master"
1010

1111
depends_on "cmake" => :build
1212
depends_on "libuv"
1313

1414
def install
1515
mkdir 'build' do
16-
system "cmake", "-DCMAKE_BUILD_TYPE=RELEASE", "-DCASS_BUILD_STATIC=ON", "-DCMAKE_INSTALL_PREFIX:PATH=#{prefix}", ".."
16+
system "cmake", "-DCMAKE_BUILD_TYPE=RELEASE", "-DCASS_BUILD_STATIC=ON", "-DCMAKE_INSTALL_PREFIX:PATH=#{prefix}", "-DCMAKE_INSTALL_LIBDIR=#{lib}", ".."
1717
system "make", "install"
1818
end
1919
end

src/uuids.cpp

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ void cass_uuid_string(CassUuid uuid, char* output) {
9292
size_t pos = 0;
9393
char encoded[16];
9494
cass::encode_uuid(encoded, uuid);
95+
static const char half_byte_to_hex[] = { '0', '1', '2', '3', '4', '5', '6', '7',
96+
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
9597
for (size_t i = 0; i < 16; ++i) {
96-
char buf[3] = { '\0' };
97-
sprintf(buf, "%02x", static_cast<uint8_t>(encoded[i]));
9898
if (i == 4 || i == 6 || i == 8 || i == 10) {
9999
output[pos++] = '-';
100100
}
101-
output[pos++] = buf[0];
102-
output[pos++] = buf[1];
101+
uint8_t byte = static_cast<uint8_t>(encoded[i]);
102+
output[pos++] = half_byte_to_hex[(byte >> 4) & 0x0F];
103+
output[pos++] = half_byte_to_hex[byte & 0x0F];
103104
}
104105
output[pos] = '\0';
105106
}
@@ -120,19 +121,37 @@ CassError cass_uuid_from_string_n(const char* str,
120121
const char* pos = str;
121122
char buf[16];
122123

124+
static const char hex_to_half_byte[256] = {
125+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
126+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
127+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
128+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1,
129+
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
130+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
131+
-1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
132+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
133+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
134+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
135+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
136+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
137+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
138+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
139+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
140+
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
141+
};
142+
123143
if (str == NULL || str_length != 36) {
124144
return CASS_ERROR_LIB_BAD_PARAMS;
125145
}
126146

127147
for (size_t i = 0; i < 16; ++i) {
128148
if (*pos == '-') pos++;
129-
unsigned int byte;
130-
intptr_t bytes_left = str - pos;
131-
if (bytes_left >= 2 || !isxdigit(*pos) || !isxdigit(*(pos + 1))) {
149+
uint8_t p0 = static_cast<uint8_t>(pos[0]);
150+
uint8_t p1 = static_cast<uint8_t>(pos[1]);
151+
if (hex_to_half_byte[p0] == -1 || hex_to_half_byte[p1] == -1) {
132152
return CASS_ERROR_LIB_BAD_PARAMS;
133153
}
134-
sscanf(pos, "%2x", &byte);
135-
buf[i] = static_cast<char>(byte);
154+
buf[i] = (hex_to_half_byte[p0] << 4) + hex_to_half_byte[p1];
136155
pos += 2;
137156
}
138157

0 commit comments

Comments
 (0)