|
1 | | -use magnus::{RArray, RHash, RString, Ruby, Symbol, Value, prelude::*, r_hash::ForEach}; |
| 1 | +use magnus::{RArray, RHash, Ruby, Symbol, Value, prelude::*, r_hash::ForEach}; |
2 | 2 | use polars::frame::row::{Row, rows_to_schema_supertypes, rows_to_supertypes}; |
3 | 3 | use polars::prelude::*; |
4 | 4 |
|
@@ -128,19 +128,13 @@ fn dicts_to_rows<'a>(data: &Value, names: &'a [String], _strict: bool) -> RbResu |
128 | 128 | let ruby = Ruby::get_with(*data); |
129 | 129 | let (data, len) = get_rbseq(*data)?; |
130 | 130 | let mut rows = Vec::with_capacity(len); |
131 | | - |
132 | | - // pre-convert keys/names so we don't repeatedly create them in the loop |
133 | | - let rb_keys: Vec<(RString, Symbol)> = names |
134 | | - .iter() |
135 | | - .map(|k| (ruby.str_new(k), ruby.to_symbol(k))) |
136 | | - .collect(); |
137 | | - |
138 | 131 | for d in data.into_iter() { |
139 | 132 | let d = RHash::try_convert(d)?; |
140 | 133 |
|
141 | 134 | let mut row = Vec::with_capacity(names.len()); |
142 | | - for (k, k2) in &rb_keys { |
143 | | - let val = match d.get(*k).or_else(|| d.get(*k2)) { |
| 135 | + for k in names.iter() { |
| 136 | + // TODO improve performance |
| 137 | + let val = match d.get(k.clone()).or_else(|| d.get(ruby.to_symbol(k))) { |
144 | 138 | None => AnyValue::Null, |
145 | 139 | Some(val) => Wrap::<AnyValue>::try_convert(val)?.0, |
146 | 140 | }; |
|
0 commit comments