Author: sebor
Date: Sun Jul 8 17:42:39 2007
New Revision: 554504
URL: http://svn.apache.org/viewvc?view=rev&rev=554504
Log:
2007-07-08 Martin Sebor <[EMAIL PROTECTED]>
STDCXX-478
* locale_eq.cpp (operator==): Removed the assumption that the same
user-defined facets must be stored at the same index in the array
in order for two locales in which they are installed to compare
equal.
Modified:
incubator/stdcxx/trunk/src/locale_eq.cpp
Modified: incubator/stdcxx/trunk/src/locale_eq.cpp
URL:
http://svn.apache.org/viewvc/incubator/stdcxx/trunk/src/locale_eq.cpp?view=diff&rev=554504&r1=554503&r2=554504
==============================================================================
--- incubator/stdcxx/trunk/src/locale_eq.cpp (original)
+++ incubator/stdcxx/trunk/src/locale_eq.cpp Sun Jul 8 17:42:39 2007
@@ -112,16 +112,38 @@
if (strcmp (_C_body->_C_name, rhs._C_body->_C_name))
return false;
- _RWSTD_ASSERT (_C_body->_C_n_usr_facets == rhs._C_body->_C_n_usr_facets);
+ // highest valid index
+ const size_t maxinx =
+ rhs._C_body->_C_n_usr_facets + _RW::__rw_locale::_C_n_std_facets;
// locales with the same (non-0) number of user-defined
// facets compare equal iff all the facets are identical
for (_RWSTD_SIZE_T i = 0; i != _C_body->_C_n_usr_facets; ++i) {
- _RWSTD_ASSERT (_C_body->_C_usr_facets [i]);
- _RWSTD_ASSERT (rhs._C_body->_C_usr_facets [i]);
+ const _RW::__rw_facet* const pf = _C_body->_C_usr_facets [i];
- if (_C_body->_C_usr_facets [i] != rhs._C_body->_C_usr_facets [i])
+ _RWSTD_ASSERT (0 != pf);
+ _RWSTD_ASSERT (0 != pf->_C_pid);
+ _RWSTD_ASSERT (0 != *pf->_C_pid);
+
+ // if the facets at the same index aren't the same but their
+ // numeric id's are the locales are not equal; this check short
+ // circuits the linear lookup of the facet in rhs done below
+ if ( pf != rhs._C_body->_C_usr_facets [i]
+ && pf->_C_pid == rhs._C_body->_C_usr_facets [i]->_C_pid)
+ return false;
+
+ // find the index of the facet in rhs if it's installed there
+ size_t inx = rhs._C_body->_C_get_facet_inx (*pf->_C_pid);
+ if (maxinx <= inx || inx < _RW::__rw_locale::_C_n_std_facets)
+ return false;
+
+ // the index starts at _C_n_std_facets
+ inx -= _RW::__rw_locale::_C_n_std_facets;
+
+ // if the two facets aren't the same objects the locales aren't
+ // equal (since they may each behave differently)
+ if (pf != rhs._C_body->_C_usr_facets [inx])
return false;
}