# HG changeset patch # User Stefan Vogel # Date 1081258656 -7200 # Node ID dcffeb2c11e07a8bd82e5ae6fb05a84290b7c59a # Parent c61c01e7d6e57613106b3395155de36137187d7f Optimize #nextPut: on UnicodeStrings diff -r c61c01e7d6e5 -r dcffeb2c11e0 WriteStream.st --- a/WriteStream.st Tue Apr 06 15:34:07 2004 +0200 +++ b/WriteStream.st Tue Apr 06 15:37:36 2004 +0200 @@ -344,6 +344,7 @@ %{ /* NOCONTEXT */ +#ifndef NO_PRIM_STREAM REGISTER int pos; unsigned ch; OBJ coll; @@ -353,69 +354,89 @@ coll = __INST(collection); p = __INST(position); -#ifndef NO_PRIM_STREAM if (__isNonNilObject(coll) && __isSmallInteger(p)) { - pos = __intVal(p); - /* make 1-based */ - pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); - wL = __INST(writeLimit); + pos = __intVal(p); + /* make 1-based */ + pos = pos + 1 - __intVal( @global(PositionableStream:ZeroPosition)); + wL = __INST(writeLimit); - if ((wL == nil) - || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) { - OBJ cls; + if ((wL == nil) + || (__isSmallInteger(wL) && (pos <= __intVal(wL)))) { + OBJ cls; - cls = __qClass(coll); + cls = __qClass(coll); - rL = __INST(readLimit); - if (__isSmallInteger(rL)) { - __readLimit = __intVal(rL); - } + rL = __INST(readLimit); + if (__isSmallInteger(rL)) { + __readLimit = __intVal(rL); + } - if (cls == @global(String)) { - if (__isCharacter(anObject) - && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */ - && (pos <= __stringSize(coll))) { - __StringInstPtr(coll)->s_element[pos-1] = ch; - if ((__readLimit >= 0) && (pos >= __readLimit)) { - __INST(readLimit) = __MKSMALLINT(pos); - } - __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); - RETURN ( anObject ); - } - } else if (cls == @global(ByteArray)) { - if (__isSmallInteger(anObject) - && ((ch = __intVal(anObject)) <= 255) /* ch is unsigned */ - && (pos <= __byteArraySize(coll))) { - __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; - if ((__readLimit >= 0) && (pos >= __readLimit)) { - __INST(readLimit) = __MKSMALLINT(pos); - } - __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); - RETURN ( anObject ); - } - } else if (cls == @global(Array)) { - if (pos <= __arraySize(coll)) { - __ArrayInstPtr(coll)->a_element[pos-1] = anObject; - __STORE(coll, anObject); - if ((__readLimit >= 0) && (pos >= __readLimit)) { - __INST(readLimit) = __MKSMALLINT(pos); - } - __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); - RETURN ( anObject ); - } - } - } + if (cls == @global(String)) { + if (__isCharacter(anObject) + && ((ch = __intVal(__characterVal(anObject))) <= 255) /* ch is unsigned */ + && (pos <= __stringSize(coll))) { + __StringInstPtr(coll)->s_element[pos-1] = ch; + if ((__readLimit >= 0) && (pos >= __readLimit)) { + __INST(readLimit) = __MKSMALLINT(pos); + } + __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); + RETURN ( anObject ); + } + } else if (cls == @global(ByteArray)) { + if (__isSmallInteger(anObject) + && ((ch = __intVal(anObject)) <= 255) /* ch is unsigned */ + && (pos <= __byteArraySize(coll))) { + __ByteArrayInstPtr(coll)->ba_element[pos-1] = ch; + if ((__readLimit >= 0) && (pos >= __readLimit)) { + __INST(readLimit) = __MKSMALLINT(pos); + } + __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); + RETURN ( anObject ); + } + } else if (cls == @global(Array)) { + if (pos <= __arraySize(coll)) { + __ArrayInstPtr(coll)->a_element[pos-1] = anObject; + __STORE(coll, anObject); + if ((__readLimit >= 0) && (pos >= __readLimit)) { + __INST(readLimit) = __MKSMALLINT(pos); + } + __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); + RETURN ( anObject ); + } + } else if (cls == @global(Unicode16String)) { + if (__isCharacter(anObject) + && ((ch = __intVal(__characterVal(anObject))) <= 32768) /* ch is unsigned */ + && (pos <= __unicode16StringSize(coll))) { + __Unicode16StringInstPtr(coll)->s_element[pos-1] = ch; + if ((__readLimit >= 0) && (pos >= __readLimit)) { + __INST(readLimit) = __MKSMALLINT(pos); + } + __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); + RETURN ( anObject ); + } + } else if (cls == @global(Unicode32String)) { + if (__isCharacter(anObject) + && (pos <= __unicode32StringSize(coll))) { + __Unicode32StringInstPtr(coll)->s_element[pos-1] = __intVal(__characterVal(anObject)); + if ((__readLimit >= 0) && (pos >= __readLimit)) { + __INST(readLimit) = __MKSMALLINT(pos); + } + __INST(position) = __MKSMALLINT(__intVal(__INST(position)) + 1); + RETURN ( anObject ); + } + } + } } #endif %}. (writeLimit isNil or:[(position + 1 - ZeroPosition) <= writeLimit]) ifTrue:[ - ((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection]. - collection at:(position + 1 - ZeroPosition) put:anObject. - ((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)]. - position := position + 1. + ((position + 1 - ZeroPosition) > collection size) ifTrue:[self growCollection]. + collection at:(position + 1 - ZeroPosition) put:anObject. + ((position + 1 - ZeroPosition) > readLimit) ifTrue:[readLimit := (position + 1 - ZeroPosition)]. + position := position + 1. ] ifFalse:[ - WriteErrorSignal raiseErrorString:'write beyond writeLimit' + WriteErrorSignal raiseErrorString:'write beyond writeLimit' ]. ^anObject ! @@ -503,5 +524,5 @@ !WriteStream class methodsFor:'documentation'! version - ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.55 2003-10-23 15:45:27 cg Exp $' + ^ '$Header: /cvs/stx/stx/libbasic/WriteStream.st,v 1.56 2004-04-06 13:37:36 stefan Exp $' ! !