diff --git a/VERSIONS b/VERSIONS index 6107b192e..2072ede2e 100644 --- a/VERSIONS +++ b/VERSIONS @@ -45,6 +45,8 @@ ChucK VERSIONS log are distinguished from windows drive letters (e.g., "A:\") - (fixed) Type.of() now reports more specific array type (e.g., `string[]`) instead of generic `@array` +- (updated) calling .sort() on an array of strings will sort by string + (instead of Object pointers) - (updated, internal) dynamic array types are now cached and reused, preventing potential memory build-up across compilations diff --git a/src/core/chuck_oo.cpp b/src/core/chuck_oo.cpp index 33ad3fe68..443ad82cd 100644 --- a/src/core/chuck_oo.cpp +++ b/src/core/chuck_oo.cpp @@ -949,26 +949,30 @@ static bool ck_compare_string( t_CKUINT lhs, t_CKUINT rhs ) //----------------------------------------------------------------------------- void Chuck_ArrayInt::sort() { - if (size() == 0) return; - - // if object references - if( m_is_obj ) { - // azaday 10/24/2024 - // HACK: - // Chuck Type system reports all object arrays are of type @array - // Somehow this diverges from .typeOf(), which correctly returns "string[]" - // instead we try dynamic_casting the first element to Chuck_String - // to determine if this is a string array - // if this is a string array, sort as strings - if( dynamic_cast((Chuck_Object*)m_vector[0]) ) { + // check size + if( size() == 0 ) return; + + // if object references | 1.5.3.5 (azaday) added + if( m_is_obj ) + { + // if this is a string[] + if( this->type_ref->array_depth == 1 && this->type_ref->base_name == "string" ) + { + // sort as string array std::sort( m_vector.begin(), m_vector.end(), ck_compare_string ); - } else { + } + else // not string object array + { // sort object pointers as unsigned ints std::sort( m_vector.begin(), m_vector.end() ); } } - // if not object references, sort as signed ints - else std::sort( m_vector.begin(), m_vector.end(), ck_compare_sint ); + // if not object references + else + { + // sort as signed ints + std::sort( m_vector.begin(), m_vector.end(), ck_compare_sint ); + } }