summaryrefslogtreecommitdiffstats
path: root/generic/tclBinary.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-31 22:23:15 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2019-01-31 22:23:15 (GMT)
commitd0613a05568e1c78a1c0f7e499a334089ec7809b (patch)
treedef1662319d2750ebfeaaf48d7f178d11e5af0e7 /generic/tclBinary.c
parent4c3bb3d6ba6b55372b33667c7907ddc552582e07 (diff)
downloadtcl-d0613a05568e1c78a1c0f7e499a334089ec7809b.zip
tcl-d0613a05568e1c78a1c0f7e499a334089ec7809b.tar.gz
tcl-d0613a05568e1c78a1c0f7e499a334089ec7809b.tar.bz2
Make TclIsPureByteArray() a macro, since it's only doing a single compare. Other internal simplifications/code duplication. No functional change, only optimizations
Diffstat (limited to 'generic/tclBinary.c')
-rw-r--r--generic/tclBinary.c72
1 files changed, 17 insertions, 55 deletions
diff --git a/generic/tclBinary.c b/generic/tclBinary.c
index f069090..5b26b2f 100644
--- a/generic/tclBinary.c
+++ b/generic/tclBinary.c
@@ -57,12 +57,9 @@
static void DupByteArrayInternalRep(Tcl_Obj *srcPtr,
Tcl_Obj *copyPtr);
-static void DupProperByteArrayInternalRep(Tcl_Obj *srcPtr,
- Tcl_Obj *copyPtr);
static int FormatNumber(Tcl_Interp *interp, int type,
Tcl_Obj *src, unsigned char **cursorPtr);
static void FreeByteArrayInternalRep(Tcl_Obj *objPtr);
-static void FreeProperByteArrayInternalRep(Tcl_Obj *objPtr);
static int GetFormatSpec(const char **formatPtr, char *cmdPtr,
int *countPtr, int *flagsPtr);
static Tcl_Obj * ScanNumber(unsigned char *buffer, int type,
@@ -248,10 +245,10 @@ static const EnsembleImplMap decodeMap[] = {
* over which bytearray values can be useful in the meanwhile.
*/
-static const Tcl_ObjType properByteArrayType = {
+const Tcl_ObjType tclPureByteArrayType = {
"bytearray",
- FreeProperByteArrayInternalRep,
- DupProperByteArrayInternalRep,
+ FreeByteArrayInternalRep,
+ DupByteArrayInternalRep,
UpdateStringOfByteArray,
NULL
};
@@ -287,13 +284,6 @@ typedef struct ByteArray {
#define SET_BYTEARRAY(irPtr, baPtr) \
(irPtr)->twoPtrValue.ptr1 = (void *) (baPtr)
-int
-TclIsPureByteArray(
- Tcl_Obj * objPtr)
-{
- return objPtr->typePtr == &properByteArrayType;
-}
-
/*
*----------------------------------------------------------------------
*
@@ -425,7 +415,7 @@ Tcl_SetByteArrayObj(
}
SET_BYTEARRAY(&ir, byteArrayPtr);
- Tcl_StoreIntRep(objPtr, &properByteArrayType, &ir);
+ Tcl_StoreIntRep(objPtr, &tclPureByteArrayType, &ir);
}
/*
@@ -453,13 +443,13 @@ Tcl_GetByteArrayFromObj(
* array of bytes in the ByteArray object. */
{
ByteArray *baPtr;
- const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
if (irPtr == NULL) {
irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
if (irPtr == NULL) {
SetByteArrayFromAny(NULL, objPtr);
- irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
if (irPtr == NULL) {
irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
}
@@ -511,12 +501,12 @@ Tcl_SetByteArrayLength(
Tcl_Panic("%s called with shared object", "Tcl_SetByteArrayLength");
}
- irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
if (irPtr == NULL) {
irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
if (irPtr == NULL) {
SetByteArrayFromAny(NULL, objPtr);
- irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
if (irPtr == NULL) {
irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
}
@@ -562,7 +552,7 @@ SetByteArrayFromAny(
ByteArray *byteArrayPtr;
Tcl_ObjIntRep ir;
- if (objPtr->typePtr == &properByteArrayType) {
+ if (objPtr->typePtr == &tclPureByteArrayType) {
return TCL_OK;
}
if (objPtr->typePtr == &tclByteArrayType) {
@@ -586,7 +576,7 @@ SetByteArrayFromAny(
SET_BYTEARRAY(&ir, byteArrayPtr);
Tcl_StoreIntRep(objPtr,
- improper ? &tclByteArrayType : &properByteArrayType, &ir);
+ improper ? &tclByteArrayType : &tclPureByteArrayType, &ir);
return TCL_OK;
}
@@ -611,14 +601,7 @@ static void
FreeByteArrayInternalRep(
Tcl_Obj *objPtr) /* Object with internal rep to free. */
{
- ckfree(GET_BYTEARRAY(TclFetchIntRep(objPtr, &tclByteArrayType)));
-}
-
-static void
-FreeProperByteArrayInternalRep(
- Tcl_Obj *objPtr) /* Object with internal rep to free. */
-{
- ckfree(GET_BYTEARRAY(TclFetchIntRep(objPtr, &properByteArrayType)));
+ ckfree(GET_BYTEARRAY(&(objPtr->internalRep)));
}
/*
@@ -647,37 +630,16 @@ DupByteArrayInternalRep(
ByteArray *srcArrayPtr, *copyArrayPtr;
Tcl_ObjIntRep ir;
- srcArrayPtr = GET_BYTEARRAY(TclFetchIntRep(srcPtr, &tclByteArrayType));
- length = srcArrayPtr->used;
-
- copyArrayPtr = ckalloc(BYTEARRAY_SIZE(length));
- copyArrayPtr->used = length;
- copyArrayPtr->allocated = length;
- memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, (size_t) length);
-
- SET_BYTEARRAY(&ir, copyArrayPtr);
- Tcl_StoreIntRep(copyPtr, &tclByteArrayType, &ir);
-}
-
-static void
-DupProperByteArrayInternalRep(
- Tcl_Obj *srcPtr, /* Object with internal rep to copy. */
- Tcl_Obj *copyPtr) /* Object with internal rep to set. */
-{
- unsigned int length;
- ByteArray *srcArrayPtr, *copyArrayPtr;
- Tcl_ObjIntRep ir;
-
- srcArrayPtr = GET_BYTEARRAY(TclFetchIntRep(srcPtr, &properByteArrayType));
+ srcArrayPtr = GET_BYTEARRAY(&(srcPtr->internalRep));
length = srcArrayPtr->used;
copyArrayPtr = ckalloc(BYTEARRAY_SIZE(length));
copyArrayPtr->used = length;
copyArrayPtr->allocated = length;
- memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, (size_t) length);
+ memcpy(copyArrayPtr->bytes, srcArrayPtr->bytes, length);
SET_BYTEARRAY(&ir, copyArrayPtr);
- Tcl_StoreIntRep(copyPtr, &properByteArrayType, &ir);
+ Tcl_StoreIntRep(copyPtr, srcPtr->typePtr, &ir);
}
/*
@@ -702,7 +664,7 @@ UpdateStringOfByteArray(
Tcl_Obj *objPtr) /* ByteArray object whose string rep to
* update. */
{
- const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ const Tcl_ObjIntRep *irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
ByteArray *byteArrayPtr = GET_BYTEARRAY(irPtr);
unsigned char *src = byteArrayPtr->bytes;
unsigned int i, length = byteArrayPtr->used;
@@ -777,12 +739,12 @@ TclAppendBytesToByteArray(
length = (unsigned int)len;
- irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
if (irPtr == NULL) {
irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
if (irPtr == NULL) {
SetByteArrayFromAny(NULL, objPtr);
- irPtr = TclFetchIntRep(objPtr, &properByteArrayType);
+ irPtr = TclFetchIntRep(objPtr, &tclPureByteArrayType);
if (irPtr == NULL) {
irPtr = TclFetchIntRep(objPtr, &tclByteArrayType);
}