Mercurial > projects > ldc
comparison tango/lib/compiler/llvmdc/adi.d @ 291:068cb3c60afb trunk
[svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
Changed array comparison runtime support to pass the array typeinfo instead of the element typeinfo. This allows a cleaner and faster implementation.
author | lindquist |
---|---|
date | Sat, 21 Jun 2008 21:16:26 +0200 |
parents | 0db62b770a49 |
children | eb110c4730c0 |
comparison
equal
deleted
inserted
replaced
290:ebaf65fc4726 | 291:068cb3c60afb |
---|---|
376 */ | 376 */ |
377 | 377 |
378 extern (C) int _adEq(Array a1, Array a2, TypeInfo ti) | 378 extern (C) int _adEq(Array a1, Array a2, TypeInfo ti) |
379 { | 379 { |
380 debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); | 380 debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); |
381 | |
381 if (a1.length != a2.length) | 382 if (a1.length != a2.length) |
382 return 0; // not equal | 383 return 0; // not equal |
383 auto sz = ti.tsize(); | 384 else if (a1.ptr == a2.ptr) |
384 auto p1 = a1.ptr; | 385 return 1; // equal |
385 auto p2 = a2.ptr; | 386 |
386 | 387 // let typeinfo decide |
387 /+ | 388 return ti.equals(&a1, &a2); |
388 for (int i = 0; i < a1.length; i++) | |
389 { | |
390 printf("%4x %4x\n", (cast(short*)p1)[i], (cast(short*)p2)[i]); | |
391 } | |
392 +/ | |
393 | |
394 if (sz == 1) | |
395 // We should really have a ti.isPOD() check for this | |
396 return (memcmp(p1, p2, a1.length) == 0); | |
397 | |
398 for (size_t i = 0; i < a1.length; i++) | |
399 { | |
400 if (!ti.equals(p1 + i * sz, p2 + i * sz)) | |
401 return 0; // not equal | |
402 } | |
403 return 1; // equal | |
404 } | 389 } |
405 | 390 |
406 unittest | 391 unittest |
407 { | 392 { |
408 debug(adi) printf("array.Eq unittest\n"); | 393 debug(adi) printf("array.Eq unittest\n"); |
421 */ | 406 */ |
422 | 407 |
423 extern (C) int _adCmp(Array a1, Array a2, TypeInfo ti) | 408 extern (C) int _adCmp(Array a1, Array a2, TypeInfo ti) |
424 { | 409 { |
425 debug(adi) printf("adCmp()\n"); | 410 debug(adi) printf("adCmp()\n"); |
411 | |
412 if (a1.ptr == a2.ptr && | |
413 a1.length == a2.length) | |
414 return 0; | |
415 | |
426 auto len = a1.length; | 416 auto len = a1.length; |
427 if (a2.length < len) | 417 if (a2.length < len) |
428 len = a2.length; | 418 len = a2.length; |
429 auto sz = ti.tsize(); | 419 |
430 void *p1 = a1.ptr; | 420 // let typeinfo decide |
431 void *p2 = a2.ptr; | 421 return ti.compare(&a1, &a2); |
432 | |
433 if (sz == 1) | |
434 { // We should really have a ti.isPOD() check for this | |
435 auto c = memcmp(p1, p2, len); | |
436 if (c) | |
437 return c; | |
438 } | |
439 else | |
440 { | |
441 for (size_t i = 0; i < len; i++) | |
442 { | |
443 auto c = ti.compare(p1 + i * sz, p2 + i * sz); | |
444 if (c) | |
445 return c; | |
446 } | |
447 } | |
448 if (a1.length == a2.length) | |
449 return 0; | |
450 return (a1.length > a2.length) ? 1 : -1; | |
451 } | 422 } |
452 | 423 |
453 unittest | 424 unittest |
454 { | 425 { |
455 debug(adi) printf("array.Cmp unittest\n"); | 426 debug(adi) printf("array.Cmp unittest\n"); |