Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Approved by: Matthias Brantner
Approved revision: 10955
Merged at revision: 10954
Proposed branch: lp:~paul-lucas/zorba/pjl-misc
Merge into: lp:zorba
Diff against target: 150 lines (+32/-16)
2 files modified
src/util/string/rep_base.h (+7/-3)
src/util/string/rstring.h (+25/-13)
To merge this branch: bzr merge lp:~paul-lucas/zorba/pjl-misc
Reviewer Review Type Date Requested Status
Matthias Brantner Approve
Paul J. Lucas Approve
Review via email: mp+116894@code.launchpad.net

Commit message

1. Tweaked equals().
2. Added "const&" to std_string function arguments.

Description of the change

1. Tweaked equals().
2. Added "const&" to std_string function arguments.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2012-07-26T15-47-06.784Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1. Got: 1 Approve.

Revision history for this message
Matthias Brantner (matthias-brantner) wrote :

Shouldn't the following be rewritten for performance:

return s1_n == s2_n && (s1 == s2 || std::memcmp( s1, s2, s1_n ) == 0);

=>

return s1_n == s2_n && (std::memcmp( s1, s2, s1_n ) == 0 ||s1 == s2);

review: Needs Information
Revision history for this message
Paul J. Lucas (paul-lucas) wrote :

No because || is evaluated left-to-right. If s1 == s2, then there's no point in doing an expensive memcmp().

Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job pjl-misc-2012-07-26T17-07-02.673Z is finished. The final status was:

All tests succeeded!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/util/string/rep_base.h'
--- src/util/string/rep_base.h 2012-07-24 08:48:48 +0000
+++ src/util/string/rep_base.h 2012-07-26 15:45:26 +0000
@@ -197,8 +197,10 @@
197 }197 }
198198
199 /**199 /**
200 * Checks whether this representation is shared.200 * Checks if the given shared-count indicates whether some string's
201 * representation is shared.
201 *202 *
203 * @param count The shared-count to check.
202 * @return Returns \c true only if it is.204 * @return Returns \c true only if it is.
203 */205 */
204 static bool is_shared( count_type count ) {206 static bool is_shared( count_type count ) {
@@ -206,7 +208,7 @@
206 }208 }
207209
208 /**210 /**
209 * Checks whether this representation is unsharable.211 * Checks whether this representation is sharable.
210 *212 *
211 * @return Returns \c true only if it is.213 * @return Returns \c true only if it is.
212 */214 */
@@ -215,8 +217,10 @@
215 }217 }
216218
217 /**219 /**
218 * Checks whether this representation is unsharable.220 * Checks if the given shared-count indicates whether some string's
221 * representation is sharable.
219 *222 *
223 * @param count The shared-count to check.
220 * @return Returns \c true only if it is.224 * @return Returns \c true only if it is.
221 */225 */
222 static bool is_sharable( count_type count ) {226 static bool is_sharable( count_type count ) {
223227
=== modified file 'src/util/string/rstring.h'
--- src/util/string/rstring.h 2012-07-24 08:48:48 +0000
+++ src/util/string/rstring.h 2012-07-26 15:45:26 +0000
@@ -2943,7 +2943,7 @@
2943 * @return Returns \c true only if \a s1 \c == \a s2.2943 * @return Returns \c true only if \a s1 \c == \a s2.
2944 */2944 */
2945inline bool equals( char const *s1, size_t s1_n, char const *s2, size_t s2_n ) {2945inline bool equals( char const *s1, size_t s1_n, char const *s2, size_t s2_n ) {
2946 return s1_n == s2_n && std::memcmp( s1, s2, s1_n ) == 0;2946 return s1_n == s2_n && (s1 == s2 || std::memcmp( s1, s2, s1_n ) == 0);
2947}2947}
29482948
2949template<class Rep> inline bool2949template<class Rep> inline bool
@@ -2957,12 +2957,14 @@
2957}2957}
29582958
2959template<class Rep> inline bool2959template<class Rep> inline bool
2960operator==( rstring<Rep> const &s1, typename rstring<Rep>::std_string s2 ) {2960operator==( rstring<Rep> const &s1,
2961 typename rstring<Rep>::std_string const &s2 ) {
2961 return equals( s1.data(), s1.size(), s2.data(), s2.size() );2962 return equals( s1.data(), s1.size(), s2.data(), s2.size() );
2962}2963}
29632964
2964template<class Rep> inline bool2965template<class Rep> inline bool
2965operator==( typename rstring<Rep>::std_string s1, rstring<Rep> const &s2 ) {2966operator==( typename rstring<Rep>::std_string const &s1,
2967 rstring<Rep> const &s2 ) {
2966 return equals( s1.data(), s1.size(), s2.data(), s2.size() );2968 return equals( s1.data(), s1.size(), s2.data(), s2.size() );
2967}2969}
29682970
@@ -2989,12 +2991,14 @@
2989}2991}
29902992
2991template<class Rep> inline bool2993template<class Rep> inline bool
2992operator!=( rstring<Rep> const &s1, typename rstring<Rep>::std_string s2 ) {2994operator!=( rstring<Rep> const &s1,
2995 typename rstring<Rep>::std_string const &s2 ) {
2993 return !(s1 == s2);2996 return !(s1 == s2);
2994}2997}
29952998
2996template<class Rep> inline bool2999template<class Rep> inline bool
2997operator!=( typename rstring<Rep>::std_string s1, rstring<Rep> const &s2 ) {3000operator!=( typename rstring<Rep>::std_string const &s1,
3001 rstring<Rep> const &s2 ) {
2998 return !(s1 == s2);3002 return !(s1 == s2);
2999}3003}
30003004
@@ -3019,12 +3023,14 @@
3019}3023}
30203024
3021template<class Rep> inline bool3025template<class Rep> inline bool
3022operator<( rstring<Rep> const &s1, typename rstring<Rep>::std_string s2 ) {3026operator<( rstring<Rep> const &s1,
3027 typename rstring<Rep>::std_string const &s2 ) {
3023 return s1.compare( s2 ) < 0;3028 return s1.compare( s2 ) < 0;
3024}3029}
30253030
3026template<class Rep> inline bool3031template<class Rep> inline bool
3027operator<( typename rstring<Rep>::std_string s1, rstring<Rep> const &s2 ) {3032operator<( typename rstring<Rep>::std_string const &s1,
3033 rstring<Rep> const &s2 ) {
3028 return s2.compare( s1 ) > 0;3034 return s2.compare( s1 ) > 0;
3029}3035}
30303036
@@ -3049,12 +3055,14 @@
3049}3055}
30503056
3051template<class Rep> inline bool3057template<class Rep> inline bool
3052operator<=( rstring<Rep> const &s1, typename rstring<Rep>::std_string s2 ) {3058operator<=( rstring<Rep> const &s1,
3059 typename rstring<Rep>::std_string const &s2 ) {
3053 return s1.compare( s2 ) <= 0;3060 return s1.compare( s2 ) <= 0;
3054}3061}
30553062
3056template<class Rep> inline bool3063template<class Rep> inline bool
3057operator<=( typename rstring<Rep>::std_string s1, rstring<Rep> const &s2 ) {3064operator<=( typename rstring<Rep>::std_string const &s1,
3065 rstring<Rep> const &s2 ) {
3058 return s2.compare( s1 ) >= 0;3066 return s2.compare( s1 ) >= 0;
3059}3067}
30603068
@@ -3079,12 +3087,14 @@
3079}3087}
30803088
3081template<class Rep> inline bool3089template<class Rep> inline bool
3082operator>( rstring<Rep> const &s1, typename rstring<Rep>::std_string s2 ) {3090operator>( rstring<Rep> const &s1,
3091 typename rstring<Rep>::std_string const &s2 ) {
3083 return s1.compare( s2 ) > 0;3092 return s1.compare( s2 ) > 0;
3084}3093}
30853094
3086template<class Rep> inline bool3095template<class Rep> inline bool
3087operator>( typename rstring<Rep>::std_string s1, rstring<Rep> const &s2 ) {3096operator>( typename rstring<Rep>::std_string const &s1,
3097 rstring<Rep> const &s2 ) {
3088 return s2.compare( s1 ) < 0;3098 return s2.compare( s1 ) < 0;
3089}3099}
30903100
@@ -3109,12 +3119,14 @@
3109}3119}
31103120
3111template<class Rep> inline bool3121template<class Rep> inline bool
3112operator>=( rstring<Rep> const &s1, typename rstring<Rep>::std_string s2 ) {3122operator>=( rstring<Rep> const &s1,
3123 typename rstring<Rep>::std_string const &s2 ) {
3113 return s1.compare( s2 ) >= 0;3124 return s1.compare( s2 ) >= 0;
3114}3125}
31153126
3116template<class Rep> inline bool3127template<class Rep> inline bool
3117operator>=( typename rstring<Rep>::std_string s1, rstring<Rep> const &s2 ) {3128operator>=( typename rstring<Rep>::std_string const &s1,
3129 rstring<Rep> const &s2 ) {
3118 return s2.compare( s1 ) <= 0;3130 return s2.compare( s1 ) <= 0;
3119}3131}
31203132

Subscribers

People subscribed via source and target branches