Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/result_response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ namespace cass {
class DataTypeDecoder {
public:
DataTypeDecoder(char* input)
: buffer_(input) { }
: buffer_(input) {
native_types_.init_class_names();
Copy link
Contributor

@mpenick mpenick Jan 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very expensive and would have to be initialized for each type decoded for every result set.

}

char* buffer() const { return buffer_; }

Expand All @@ -129,14 +131,7 @@ class DataTypeDecoder {

default:
if (value_type < CASS_VALUE_TYPE_LAST_ENTRY) {
if (data_type_cache_[value_type]) {
return data_type_cache_[value_type];
} else {
DataType::Ptr data_type(
new DataType(static_cast<CassValueType>(value_type)));
data_type_cache_[value_type] = data_type;
return data_type;
}
return decode_simple_type(value_type);
}
break;
}
Expand All @@ -148,7 +143,24 @@ class DataTypeDecoder {
DataType::Ptr decode_custom() {
StringRef class_name;
buffer_ = decode_string(buffer_, &class_name);
return DataType::Ptr(new CustomType(class_name.to_string()));

const DataType::ConstPtr& type = native_types_.by_class_name(class_name.to_string());
if (type == DataType::NIL)
// If no mapping exists, return an actual custom type.
return DataType::Ptr(new CustomType(class_name.to_string()));
else
return type->copy();
}

DataType::Ptr decode_simple_type(uint16_t value_type) {
if (data_type_cache_[value_type]) {
return data_type_cache_[value_type];
} else {
DataType::Ptr data_type(
new DataType(static_cast<CassValueType>(value_type)));
data_type_cache_[value_type] = data_type;
return data_type;
}
}

DataType::Ptr decode_collection(CassValueType collection_type) {
Expand Down Expand Up @@ -196,6 +208,7 @@ class DataTypeDecoder {
private:
char* buffer_;
DataType::Ptr data_type_cache_[CASS_VALUE_TYPE_LAST_ENTRY];
NativeDataTypes native_types_;
};

bool ResultResponse::decode(int version, char* input, size_t size) {
Expand Down