1 // Copyright 2017 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include <fbl/string_piece.h>
6 
7 #include <fbl/algorithm.h>
8 
9 namespace fbl {
10 
compare(const StringPiece & other) const11 int StringPiece::compare(const StringPiece& other) const {
12     size_t len = min(length_, other.length_);
13     int retval = memcmp(data_, other.data_, len);
14     if (retval == 0) {
15         if (length_ == other.length_) {
16             return 0;
17         }
18         return length_ < other.length_ ? -1 : 1;
19     }
20     return retval;
21 }
22 
operator ==(const StringPiece & lhs,const StringPiece & rhs)23 bool operator==(const StringPiece& lhs, const StringPiece& rhs) {
24     return lhs.length() == rhs.length() &&
25            memcmp(lhs.data(), rhs.data(), lhs.length()) == 0;
26 }
27 
28 } // namespace fbl
29