Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #43 from outoftime/column-name-map

Precalculate a map of column names -> column indices
  • Loading branch information...
commit 8d2905f60a5ecf5d53aa30e9bde4f82a4550bb13 2 parents f6ea6d7 + e873392
@kreynolds authored
Showing with 10 additions and 4 deletions.
  1. +7 −3 lib/cassandra-cql/row.rb
  2. +3 −1 spec/spec_helper.rb
View
10 lib/cassandra-cql/row.rb
@@ -22,12 +22,12 @@ def initialize(row, schema)
@row, @schema = row, schema
@value_cache = Hash.new { |h, key|
# If it's a number and not one of our columns, assume it's an index
- if key.kind_of?(Fixnum) and !column_names.include?(key)
+ if key.kind_of?(Fixnum) and !column_indices.key?(key)
column_name = column_names[key]
column_index = key
else
column_name = key
- column_index = column_names.index(key)
+ column_index = column_indices[key]
end
if column_index.nil?
@@ -48,7 +48,11 @@ def column_names
ColumnFamily.cast(column.name, @schema.names[column.name])
end
end
-
+
+ def column_indices
+ @column_indices ||= Hash[column_names.each_with_index.to_a]
+ end
+
def column_values
column_names.map do |name|
@value_cache[name]
View
4 spec/spec_helper.rb
@@ -4,12 +4,14 @@
end
require 'rubygems'
+require 'bundler'
+Bundler.setup(:default, :test)
+
require 'yaml'
require 'rspec'
CASSANDRA_VERSION = ENV['CASSANDRA_VERSION'] || '1.1' unless defined?(CASSANDRA_VERSION)
-$LOAD_PATH << "#{File.expand_path(File.dirname(__FILE__))}/../lib"
require "cassandra-cql/#{CASSANDRA_VERSION}"
def yaml_fixture(file)
Please sign in to comment.
Something went wrong with that request. Please try again.