Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | [3396731] inline string reverse: minor further improvements |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
69c582084d9ca309d37bcc1b7b4caa22 |
User & Date: | jan.nijtmans 2011-08-29 07:25:27 |
Context
2011-08-29
| ||
10:43 | Fix eval's faulty objProc, it was actually an nreProc [Bug 3399564]. Thanks to Joe Mistachki... check-in: 6fde6aa738 user: mig tags: trunk | |
07:32 | Merge to feature branch check-in: a28c1f710a user: jan.nijtmans tags: tip-388-impl | |
07:25 | [3396731] inline string reverse: minor further improvements check-in: 69c582084d user: jan.nijtmans tags: trunk | |
2011-08-27
| ||
04:24 | 3396731 Revise the [string reverse] implementation to operate on the representation that comes in, a... check-in: dc7f1a9b04 user: dgp tags: trunk | |
Changes
Changes to generic/tclStringObj.c.
︙ | ︙ | |||
2649 2650 2651 2652 2653 2654 2655 | * * Side effects: * May allocate a new Tcl_Obj. * *--------------------------------------------------------------------------- */ | | | | | | | < < < < < < < < < < < < < < < < < < < < < < < > > > > | > > > | > | > > > > > > | 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 | * * Side effects: * May allocate a new Tcl_Obj. * *--------------------------------------------------------------------------- */ static void ReverseBytes( unsigned char *to, /* Copy bytes into here... */ unsigned char *from, /* ...from here... */ int count) /* Until this many are copied, */ /* reversing as you go. */ { unsigned char *src = from + count; if (to == from) { /* Reversing in place */ while (--src > to) { unsigned char c = *src; *src = *to; *to++ = c; } } else { while (--src >= from) { *to++ = *src; } } } Tcl_Obj * TclStringObjReverse( Tcl_Obj *objPtr) { String *stringPtr; Tcl_UniChar ch; if (TclIsPureByteArray(objPtr)) { int numBytes; unsigned char *from = Tcl_GetByteArrayFromObj(objPtr, &numBytes); if (Tcl_IsShared(objPtr)) { objPtr = Tcl_NewByteArrayObj(NULL, numBytes); } ReverseBytes(Tcl_GetByteArrayFromObj(objPtr, NULL), from, numBytes); return objPtr; } SetStringFromAny(NULL, objPtr); stringPtr = GET_STRING(objPtr); if (stringPtr->hasUnicode) { Tcl_UniChar *from = Tcl_GetUnicode(objPtr); Tcl_UniChar *src = from + stringPtr->numChars; if (Tcl_IsShared(objPtr)) { Tcl_UniChar *to; /* * Create a non-empty, pure unicode value, so we can coax * Tcl_SetObjLength into growing the unicode rep buffer. */ ch = 0; objPtr = Tcl_NewUnicodeObj(&ch, 1); Tcl_SetObjLength(objPtr, stringPtr->numChars); to = Tcl_GetUnicode(objPtr); while (--src >= from) { *to++ = *src; } } else { /* Reversing in place */ while (--src > from) { ch = *src; *src = *from; *from++ = ch; } } } if (objPtr->bytes) { int numChars = stringPtr->numChars; int numBytes = objPtr->length; char *to, *from = objPtr->bytes; |
︙ | ︙ | |||
2759 2760 2761 2762 2763 2764 2765 | while (bytesLeft) { /* * NOTE: We know that the from buffer is NUL-terminated. * It's part of the contract for objPtr->bytes values. * Thus, we can skip calling Tcl_UtfCharComplete() here. */ | < | 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 | while (bytesLeft) { /* * NOTE: We know that the from buffer is NUL-terminated. * It's part of the contract for objPtr->bytes values. * Thus, we can skip calling Tcl_UtfCharComplete() here. */ int bytesInChar = Tcl_UtfToUniChar(from, &ch); ReverseBytes((unsigned char *)to, (unsigned char *)from, bytesInChar); to += bytesInChar; from += bytesInChar; bytesLeft -= bytesInChar; |
︙ | ︙ |