This is the mail archive of the kawa@sourceware.org mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

comparing char primitives


Hello,

I'm looking to see if there's a way to compare char primitives
directly, as in

boolean javaCharEq(char c1, char c2) { return c1 == c2; }


or the like (which compiles to a simple integer comparison of
the raw values), without going through gnu.text.Char.

Kawa's char=? is defined to have character (i.e. gnu.text.Char)
parameters, so

(define (compare-chars (c1 ::char) (c2 ::char)) ::boolean
  (char=? c1 c2))

first calls gnu.text.Char#make to box each argument, and then calls char=? which immediately calls intValue() on each to unbox them again. Seems unnecessary.

My first thought was to change char=? to be a GenericProc with a
method taking chars, but then I discovered that even if I do that,
I have no way of comparing them. All of the normal equality tests
(=, eq?, eqv?, equal?) box them first (and then = fails because
the Chars aren't numeric types).

Am I correct in concluding that currently there is no way to compare
unboxed chars? It looks like that's also the case for boolean.

I examined =, eq?, eqv?, and equal? for each of the primitive types
and, as expected, = works for the numeric types (though for some reason
for floats it promotes both to doubles and then uses dcmpg rather than
fcmpg?). But for char every one of them boxes with Char#make(), and for
boolean they do silly things like

  0: iload_0
  1: ifeq 10
  4: getstatic <Field java.lang.Boolean.TRUE java.lang.Boolean>
  7: goto 13
 10: getstatic <Field java.lang.Boolean.FALSE java.lang.Boolean>
 13: iload_1
 14: ifeq 23
 17: getstatic <Field java.lang.Boolean.TRUE java.lang.Boolean>
 20: goto 26
 23: getstatic <Field java.lang.Boolean.FALSE java.lang.Boolean>

followed by comparisons of the java.lang.Boolean constants.



--
Jamison Hope
The PTR Group
www.theptrgroup.com




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]