 |
Changeset 3651
- Timestamp:
- 06/20/08 14:46:26
(5 months ago)
- Author:
- sean
- Message:
Changed array compare to call TypeInfo?.equals and TypeInfo?.compare rather than looping on comparing values. This should allow optimized type-specific comparisons to be used where applicable.
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r2974 |
r3651 |
|
| 81 | 81 | auto chi = *hi; |
|---|
| 82 | 82 | |
|---|
| 83 | | debug(adi) printf("lo = %d, hi = %d\n", lo, hi); |
|---|
| | 83 | debug(adi) printf("lo = %d, hi = %d\n", lo, hi); |
|---|
| 84 | 84 | if (clo <= 0x7F && chi <= 0x7F) |
|---|
| 85 | 85 | { |
|---|
| 86 | | debug(adi) printf("\tascii\n"); |
|---|
| | 86 | debug(adi) printf("\tascii\n"); |
|---|
| 87 | 87 | *lo = chi; |
|---|
| 88 | 88 | *hi = clo; |
|---|
| … | … | |
| 104 | 104 | break; |
|---|
| 105 | 105 | |
|---|
| 106 | | debug(adi) printf("\tstridelo = %d, stridehi = %d\n", stridelo, stridehi); |
|---|
| | 106 | debug(adi) printf("\tstridelo = %d, stridehi = %d\n", stridelo, stridehi); |
|---|
| 107 | 107 | if (stridelo == stridehi) |
|---|
| 108 | 108 | { |
|---|
| … | … | |
| 120 | 120 | memcpy(tmp.ptr, hi, stridehi); |
|---|
| 121 | 121 | memcpy(tmplo.ptr, lo, stridelo); |
|---|
| 122 | | memmove(lo + stridehi, lo + stridelo , (hi - lo) - stridelo); |
|---|
| | 122 | memmove(lo + stridehi, lo + stridelo , (hi - lo) - stridelo); |
|---|
| 123 | 123 | memcpy(lo, tmp.ptr, stridehi); |
|---|
| 124 | 124 | memcpy(hi + stridehi - stridelo, tmplo.ptr, stridelo); |
|---|
| … | … | |
| 336 | 336 | if (a.length > 1) |
|---|
| 337 | 337 | { |
|---|
| 338 | | dchar[] da = toUTF32(a); |
|---|
| | 338 | dchar[] da = toUTF32(a); |
|---|
| 339 | 339 | da.sort; |
|---|
| 340 | 340 | size_t i = 0; |
|---|
| … | … | |
| 358 | 358 | if (a.length > 1) |
|---|
| 359 | 359 | { |
|---|
| 360 | | dchar[] da = toUTF32(a); |
|---|
| | 360 | dchar[] da = toUTF32(a); |
|---|
| 361 | 361 | da.sort; |
|---|
| 362 | 362 | size_t i = 0; |
|---|
| 363 | 363 | foreach (dchar d; da) |
|---|
| 364 | 364 | { wchar[2] buf; |
|---|
| 365 | | auto t = toUTF16(buf, d); |
|---|
| | 365 | auto t = toUTF16(buf, d); |
|---|
| 366 | 366 | a[i .. i + t.length] = t[]; |
|---|
| 367 | 367 | i += t.length; |
|---|
| … | … | |
| 379 | 379 | { |
|---|
| 380 | 380 | debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); |
|---|
| | 381 | |
|---|
| | 382 | if (a1.ptr == a2.ptr) |
|---|
| | 383 | return 1; // equal |
|---|
| 381 | 384 | if (a1.length != a2.length) |
|---|
| 382 | | return 0; // not equal |
|---|
| 383 | | auto sz = ti.tsize(); |
|---|
| 384 | | auto p1 = a1.ptr; |
|---|
| 385 | | auto p2 = a2.ptr; |
|---|
| 386 | | |
|---|
| 387 | | /+ |
|---|
| 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 |
|---|
| | 385 | return 0; // not equal |
|---|
| | 386 | |
|---|
| | 387 | // We should really have a ti.isPOD() check for this |
|---|
| | 388 | if (ti.tsize() != 1) |
|---|
| | 389 | return ti.equals(&a1, &a2); |
|---|
| | 390 | return memcmp(a1.ptr, a2.ptr, a1.length) == 0; |
|---|
| 404 | 391 | } |
|---|
| 405 | 392 | |
|---|
| … | … | |
| 424 | 411 | { |
|---|
| 425 | 412 | debug(adi) printf("adCmp()\n"); |
|---|
| | 413 | |
|---|
| | 414 | if (a1.ptr == a2.ptr) |
|---|
| | 415 | return 0; |
|---|
| 426 | 416 | auto len = a1.length; |
|---|
| 427 | 417 | if (a2.length < len) |
|---|
| 428 | 418 | len = a2.length; |
|---|
| 429 | | auto sz = ti.tsize(); |
|---|
| 430 | | void *p1 = a1.ptr; |
|---|
| 431 | | void *p2 = a2.ptr; |
|---|
| 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 | | } |
|---|
| | 419 | |
|---|
| | 420 | // We should really have a ti.isPOD() check for this |
|---|
| | 421 | if (ti.tsize() != 1) |
|---|
| | 422 | return ti.compare(&a1, &a2); |
|---|
| | 423 | auto c = memcmp(a1.ptr, a2.ptr, len); |
|---|
| | 424 | if (c) |
|---|
| | 425 | return c; |
|---|
| 448 | 426 | if (a1.length == a2.length) |
|---|
| 449 | 427 | return 0; |
|---|
| 450 | | return (a1.length > a2.length) ? 1 : -1; |
|---|
| | 428 | return a1.length > a2.length ? 1 : -1; |
|---|
| 451 | 429 | } |
|---|
| 452 | 430 | |
|---|
| r2974 |
r3651 |
|
| 87 | 87 | auto chi = *hi; |
|---|
| 88 | 88 | |
|---|
| 89 | | debug(adi) printf("lo = %d, hi = %d\n", lo, hi); |
|---|
| | 89 | debug(adi) printf("lo = %d, hi = %d\n", lo, hi); |
|---|
| 90 | 90 | if (clo <= 0x7F && chi <= 0x7F) |
|---|
| 91 | 91 | { |
|---|
| 92 | | debug(adi) printf("\tascii\n"); |
|---|
| | 92 | debug(adi) printf("\tascii\n"); |
|---|
| 93 | 93 | *lo = chi; |
|---|
| 94 | 94 | *hi = clo; |
|---|
| … | … | |
| 110 | 110 | break; |
|---|
| 111 | 111 | |
|---|
| 112 | | debug(adi) printf("\tstridelo = %d, stridehi = %d\n", stridelo, stridehi); |
|---|
| | 112 | debug(adi) printf("\tstridelo = %d, stridehi = %d\n", stridelo, stridehi); |
|---|
| 113 | 113 | if (stridelo == stridehi) |
|---|
| 114 | 114 | { |
|---|
| … | … | |
| 126 | 126 | memcpy(tmp.ptr, hi, stridehi); |
|---|
| 127 | 127 | memcpy(tmplo.ptr, lo, stridelo); |
|---|
| 128 | | memmove(lo + stridehi, lo + stridelo , (hi - lo) - stridelo); |
|---|
| | 128 | memmove(lo + stridehi, lo + stridelo , (hi - lo) - stridelo); |
|---|
| 129 | 129 | memcpy(lo, tmp.ptr, stridehi); |
|---|
| 130 | 130 | memcpy(hi + cast(int) stridehi - cast(int) stridelo, tmplo.ptr, stridelo); |
|---|
| 131 | 131 | |
|---|
| 132 | 132 | lo += stridehi; |
|---|
| 133 | | hi = hi - 1 + (cast(int) stridehi - cast(int) stridelo); |
|---|
| | 133 | hi = hi - 1 + (cast(int) stridehi - cast(int) stridelo); |
|---|
| 134 | 134 | } |
|---|
| 135 | 135 | } |
|---|
| … | … | |
| 219 | 219 | */ |
|---|
| 220 | 220 | memcpy(tmp.ptr, hi, stridehi * wchar.sizeof); |
|---|
| 221 | | memcpy(hi + cast(int) stridehi - cast(int) stridelo, lo, stridelo * wchar.sizeof); |
|---|
| | 221 | memcpy(hi + cast(int) stridehi - cast(int) stridelo, lo, stridelo * wchar.sizeof); |
|---|
| 222 | 222 | memmove(lo + stridehi, lo + stridelo , (hi - (lo + stridelo)) * wchar.sizeof); |
|---|
| 223 | 223 | memcpy(lo, tmp.ptr, stridehi * wchar.sizeof); |
|---|
| 224 | 224 | |
|---|
| 225 | 225 | lo += stridehi; |
|---|
| 226 | | hi = hi - 1 + (cast(int) stridehi - cast(int) stridelo); |
|---|
| | 226 | hi = hi - 1 + (cast(int) stridehi - cast(int) stridelo); |
|---|
| 227 | 227 | } |
|---|
| 228 | 228 | } |
|---|
| … | … | |
| 490 | 490 | if (a.length > 1) |
|---|
| 491 | 491 | { |
|---|
| 492 | | dchar[] da = toUTF32(a); |
|---|
| | 492 | dchar[] da = toUTF32(a); |
|---|
| 493 | 493 | da.sort; |
|---|
| 494 | 494 | size_t i = 0; |
|---|
| … | … | |
| 512 | 512 | if (a.length > 1) |
|---|
| 513 | 513 | { |
|---|
| 514 | | dchar[] da = toUTF32(a); |
|---|
| | 514 | dchar[] da = toUTF32(a); |
|---|
| 515 | 515 | da.sort; |
|---|
| 516 | 516 | size_t i = 0; |
|---|
| 517 | 517 | foreach (dchar d; da) |
|---|
| 518 | 518 | { wchar[2] buf; |
|---|
| 519 | | auto t = toUTF16(buf, d); |
|---|
| | 519 | auto t = toUTF16(buf, d); |
|---|
| 520 | 520 | a[i .. i + t.length] = t[]; |
|---|
| 521 | 521 | i += t.length; |
|---|
| … | … | |
| 532 | 532 | extern (C) int _adEq(Array a1, Array a2, TypeInfo ti) |
|---|
| 533 | 533 | { |
|---|
| 534 | | debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); |
|---|
| | 534 | debug(adi) printf("_adEq(a1.length = %d, a2.length = %d)\n", a1.length, a2.length); |
|---|
| | 535 | |
|---|
| | 536 | if (a1.ptr == a2.ptr) |
|---|
| | 537 | return 1; // equal |
|---|
| 535 | 538 | if (a1.length != a2.length) |
|---|
| 536 | | return 0; // not equal |
|---|
| 537 | | auto sz = ti.tsize(); |
|---|
| 538 | | auto p1 = a1.ptr; |
|---|
| 539 | | auto p2 = a2.ptr; |
|---|
| 540 | | |
|---|
| 541 | | /+ |
|---|
| 542 | | for (int i = 0; i < a1.length; i++) |
|---|
| 543 | | { |
|---|
| 544 | | printf("%4x %4x\n", (cast(short*)p1)[i], (cast(short*)p2)[i]); |
|---|
| 545 | | } |
|---|
| 546 | | +/ |
|---|
| 547 | | |
|---|
| 548 | | if (sz == 1) |
|---|
| 549 | | // We should really have a ti.isPOD() check for this |
|---|
| 550 | | return (memcmp(p1, p2, a1.length) == 0); |
|---|
| 551 | | |
|---|
| 552 | | for (size_t i = 0; i < a1.length; i++) |
|---|
| 553 | | { |
|---|
| 554 | | if (!ti.equals(p1 + i * sz, p2 + i * sz)) |
|---|
| 555 | | return 0; // not equal |
|---|
| 556 | | } |
|---|
| 557 | | return 1; // equal |
|---|
| | 539 | return 0; // not equal |
|---|
| | 540 | |
|---|
| | 541 | // We should really have a ti.isPOD() check for this |
|---|
| | 542 | if (ti.tsize() != 1) |
|---|
| | 543 | return ti.equals(&a1, &a2); |
|---|
| | 544 | return memcmp(a1.ptr, a2.ptr, a1.length) == 0; |
|---|
| 558 | 545 | } |
|---|
| 559 | 546 | |
|---|
| … | … | |
| 578 | 565 | { |
|---|
| 579 | 566 | debug(adi) printf("adCmp()\n"); |
|---|
| | 567 | |
|---|
| | 568 | if (a1.ptr == a2.ptr) |
|---|
| | 569 | return 0; |
|---|
| 580 | 570 | auto len = a1.length; |
|---|
| 581 | 571 | if (a2.length < len) |
|---|
| 582 | 572 | len = a2.length; |
|---|
| 583 | | auto sz = ti.tsize(); |
|---|
| 584 | | void *p1 = a1.ptr; |
|---|
| 585 | | void *p2 = a2.ptr; |
|---|
| 586 | | |
|---|
| 587 | | if (sz == 1) |
|---|
| 588 | | { // We should really have a ti.isPOD() check for this |
|---|
| 589 | | auto c = memcmp(p1, p2, len); |
|---|
| 590 | | if (c) |
|---|
| 591 | | return c; |
|---|
| 592 | | } |
|---|
| 593 | | else |
|---|
| 594 | | { |
|---|
| 595 | | for (size_t i = 0; i < len; i++) |
|---|
| 596 | | { |
|---|
| 597 | | auto c = ti.compare(p1 + i * sz, p2 + i * sz); |
|---|
| 598 | | if (c) |
|---|
| 599 | | return c; |
|---|
| 600 | | } |
|---|
| 601 | | } |
|---|
| | 573 | |
|---|
| | 574 | // We should really have a ti.isPOD() check for this |
|---|
| | 575 | if (ti.tsize() != 1) |
|---|
| | 576 | return ti.compare(&a1, &a2); |
|---|
| | 577 | auto c = memcmp(a1.ptr, a2.ptr, len); |
|---|
| | 578 | if (c) |
|---|
| | 579 | return c; |
|---|
| 602 | 580 | if (a1.length == a2.length) |
|---|
| 603 | 581 | return 0; |
|---|
| 604 | | return (a1.length > a2.length) ? 1 : -1; |
|---|
| | 582 | return a1.length > a2.length ? 1 : -1; |
|---|
| 605 | 583 | } |
|---|
| 606 | 584 | |
|---|
Download in other formats:
|
 |