@@ -35,7 +35,6 @@ ParamValue::init_noclear(ustring _name, TypeDesc _type, int _nvalues,
3535 m_type = _type;
3636 m_nvalues = _nvalues;
3737 m_interp = _interp;
38- size_t n = (size_t )(m_nvalues * m_type.numelements ());
3938 size_t size = (size_t )(m_nvalues * m_type.size ());
4039 bool small = (size <= sizeof (m_data));
4140
@@ -58,9 +57,9 @@ ParamValue::init_noclear(ustring _name, TypeDesc _type, int _nvalues,
5857 m_nonlocal = true ;
5958 }
6059 if (m_type.basetype == TypeDesc::STRING && !_from_ustring) {
61- if (ustring* u = (ustring*) data ())
62- for (size_t i = 0 ; i < n; ++i )
63- u[i] = ustring (u[i] .c_str ());
60+ // Convert non-ustrings to ustrings
61+ for (ustring& u : as_span<ustring>() )
62+ u = ustring (u.c_str ());
6463 }
6564 } else {
6665 // Big enough to warrant a malloc, but the caller said don't
@@ -126,17 +125,13 @@ template<class T>
126125static void
127126parse_elements (string_view value, ParamValue& p)
128127{
129- using namespace Strutil ;
130- TypeDesc type = p.type ();
131- int num_items = type.numelements () * type.aggregate ;
132- T* data = (T*)p.data ();
133- // Erase any leading whitespace
128+ auto data = p.as_span <T>();
134129 value.remove_prefix (value.find_first_not_of (" \t " ));
135- for (int i = 0 ; i < num_items; ++i ) {
130+ for (auto && d : data ) {
136131 // Make a temporary copy so we for sure have a 0-terminated string.
137132 std::string temp = value;
138133 // Grab the first value from it
139- data[i] = from_string<T>(temp);
134+ d = Strutil:: from_string<T>(temp);
140135 // Skip the value (eat until we find a delimiter -- space, comma, tab)
141136 value.remove_prefix (value.find_first_of (" ,\t " ));
142137 // Skip the delimiter
0 commit comments