-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrb_u_string_equal.c
33 lines (25 loc) · 974 Bytes
/
rb_u_string_equal.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "rb_includes.h"
/* @overload ==(other)
* @param [U::String, #to_str] other
* @return [Boolean] True if the receiver’s bytes equal those of OTHER
* @see #<=>
* @see #eql? */
VALUE
rb_u_string_equal(VALUE self, VALUE rbother)
{
if (self == rbother)
return Qtrue;
if (RTEST(rb_obj_is_kind_of(rbother, rb_cUString)))
return rb_u_string_eql(self, rbother);
if (!rb_respond_to(rbother, rb_intern("to_str")))
return Qfalse;
const struct rb_u_string *string = RVAL2USTRING(self);
const struct rb_u_string *other = RVAL2USTRING_ANY(rbother);
const char *p = USTRING_STR(string);
const char *q = USTRING_STR(other);
if (p == q)
return Qtrue;
long p_length = USTRING_LENGTH(string);
long q_length = USTRING_LENGTH(other);
return p_length == q_length && memcmp(p, q, q_length) == 0 ? Qtrue : Qfalse;
}