Many hyperlinks are disabled.
Use anonymous login
to enable hyperlinks.
Overview
Comment: | Make simplificiations possible when we know just bytes are getting copied without complications of encodings |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | dgp-writebytes-optimize |
Files: | files | file ages | folders |
SHA1: |
eb68cdfbc14c7863b2a3a29281c19c04 |
User & Date: | dgp 2014-08-21 04:13:35 |
Context
2014-08-21
| ||
04:13 | Make simplificiations possible when we know just bytes are getting copied without complications of e... Closed-Leaf check-in: eb68cdfbc1 user: dgp tags: dgp-writebytes-optimize | |
2014-08-20
| ||
21:44 | Copy Write() to WriteBytes() to create an arena for performance hacking. check-in: 6e08d8924a user: dgp tags: dgp-writebytes-optimize | |
Changes
Changes to generic/tclIO.c.
︙ | ︙ | |||
224 225 226 227 228 229 230 | static Tcl_Obj * FixLevelCode(Tcl_Obj *msg); static void SpliceChannel(Tcl_Channel chan); static void CutChannel(Tcl_Channel chan); static int WillRead(Channel *chanPtr); #define WriteChars(chanPtr, src, srcLen) \ Write(chanPtr, src, srcLen, chanPtr->state->encoding) | < < | 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | static Tcl_Obj * FixLevelCode(Tcl_Obj *msg); static void SpliceChannel(Tcl_Channel chan); static void CutChannel(Tcl_Channel chan); static int WillRead(Channel *chanPtr); #define WriteChars(chanPtr, src, srcLen) \ Write(chanPtr, src, srcLen, chanPtr->state->encoding) static int WriteBytes(Channel *chanPtr, const char *src, int srcLen); /* * Simplifying helper macros. All may use their argument(s) multiple times. * The ANSI C "prototypes" for the macros are listed below, together with a * short description of what the macro does. |
︙ | ︙ | |||
3895 3896 3897 3898 3899 3900 3901 | WriteBytes( Channel *chanPtr, /* The channel to buffer output for. */ const char *src, /* UTF-8 string to write. */ int srcLen) /* Length of UTF-8 string in bytes. */ { ChannelState *statePtr = chanPtr->state; /* State info for channel */ | < < | < < < < < < | | | < < < < | | | > | < < < | < < | | < < | < < | < > | < | | | | | | | 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 | WriteBytes( Channel *chanPtr, /* The channel to buffer output for. */ const char *src, /* UTF-8 string to write. */ int srcLen) /* Length of UTF-8 string in bytes. */ { ChannelState *statePtr = chanPtr->state; /* State info for channel */ char *nextNewLine = NULL; int saved = 0, total = 0, flushed = 0, needNlFlush = 0; if (srcLen) { WillWrite(chanPtr); } if (GotFlag(statePtr, CHANNEL_LINEBUFFERED) || (statePtr->outputTranslation != TCL_TRANSLATE_LF)) { nextNewLine = memchr(src, '\n', srcLen); } while (srcLen + saved > 0) { ChannelBuffer *bufPtr; char *dst; int dstLen, srcLimit = srcLen; if (nextNewLine) { srcLimit = nextNewLine - src; } /* Get space to write into */ bufPtr = statePtr->curOutPtr; if (bufPtr == NULL) { bufPtr = AllocChannelBuffer(statePtr->bufSize); statePtr->curOutPtr = bufPtr; } if (saved) { /* Start new buffer with \n straddled over from last one */ InsertPoint(bufPtr)[0] = '\n'; bufPtr->nextAdded++; saved = 0; needNlFlush = 1; } PreserveChannelBuffer(bufPtr); dst = InsertPoint(bufPtr); dstLen = SpaceLeft(bufPtr); if (srcLimit < 0) { srcLimit = strlen(src); } if (srcLimit > dstLen) { srcLimit = dstLen; } memcpy(dst, src, (size_t) srcLimit); bufPtr->nextAdded += srcLimit; src += srcLimit; srcLen -= srcLimit; total += srcLimit; dst += srcLimit; dstLen -= srcLimit; if (src == nextNewLine && dstLen > 0) { static char crln[3] = "\r\n"; char *nl = NULL; int nlLen = 0; switch (statePtr->outputTranslation) { |
︙ | ︙ | |||
3991 3992 3993 3994 3995 3996 3997 | nl = crln; nlLen = 2; break; default: Tcl_Panic("unknown output translation requested"); break; } | | < < < < | < | | | | < < < < < | < | < < < < < > < | < | 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 | nl = crln; nlLen = 2; break; default: Tcl_Panic("unknown output translation requested"); break; } memcpy(dst, nl, (size_t) nlLen); bufPtr->nextAdded += nlLen; src++; srcLen--; total += nlLen; dst += nlLen; dstLen -= nlLen; nextNewLine = memchr(src, '\n', srcLen); needNlFlush = 1; } if (IsBufferOverflowing(bufPtr)) { /* Can only happend when \r\n straddles buffers */ saved = 1; bufPtr->nextAdded = bufPtr->bufLength; } if (IsBufferFull(bufPtr)) { if (FlushChannel(NULL, chanPtr, 0) != 0) { ReleaseChannelBuffer(bufPtr); return -1; } /* TODO: ought to add bytes actually flushed */ flushed += statePtr->bufSize; needNlFlush = 0; } ReleaseChannelBuffer(bufPtr); } if ((flushed < total) && (GotFlag(statePtr, CHANNEL_UNBUFFERED) || (needNlFlush && GotFlag(statePtr, CHANNEL_LINEBUFFERED)))) { if (FlushChannel(NULL, chanPtr, 0) != 0) { return -1; |
︙ | ︙ |