Skip to content

Commit

Permalink
add String>>#= primitive
Browse files Browse the repository at this point in the history
2008-05-27  Paolo Bonzini  <bonzini@gnu.org>

	* kernel/ByteArray.st: Use VMpr_ArrayedCollection_equal.
	* kernel/String.st: Use VMpr_ArrayedCollection_equal.

libgst:
2008-05-27  Paolo Bonzini  <bonzini@gnu.org>

	* libgst/prims.def: Add VMpr_ArrayedCollection_equal.
  • Loading branch information
bonzini committed May 27, 2008
1 parent 10bfc3e commit 0f9276d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 11 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2008-05-27 Paolo Bonzini <bonzini@gnu.org>

* kernel/ByteArray.st: Use VMpr_ArrayedCollection_equal.
* kernel/String.st: Use VMpr_ArrayedCollection_equal.

2008-05-27 Paolo Bonzini <bonzini@gnu.org>

* kernel/ArrayColl.st: Avoid useless checks.
Expand Down
8 changes: 8 additions & 0 deletions kernel/ByteArray.st
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,14 @@ a String''s elements are characters.'>
self checkIndexableBounds: index put: value
]

= aCollection [
"Answer whether the receiver's items match those in aCollection"

<category: 'basic'>
<primitive: VMpr_ArrayedCollection_equal>
^false
]

hash [
"Answer an hash value for the receiver"

Expand Down
12 changes: 3 additions & 9 deletions kernel/String.st
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,12 @@ or assumed to be the system default.'>
^false
]

= aString [
= aCollection [
"Answer whether the receiver's items match those in aCollection"

<category: 'basic'>
aString isString ifFalse: [^super = aString].

"Also a String, no need to check the encoding."
self size = aString size ifFalse: [^false].
self hash == aString hash ifFalse: [^false].
1 to: self size
do: [:i | (self at: i) == (aString at: i) ifFalse: [^false]].
^true
<primitive: VMpr_ArrayedCollection_equal>
^super = aCollection
]

, aString [
Expand Down
4 changes: 4 additions & 0 deletions libgst/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
2008-05-27 Paolo Bonzini <bonzini@gnu.org>

* libgst/prims.def: Add VMpr_ArrayedCollection_equal.

2008-05-22 Paolo Bonzini <bonzini@gnu.org>

* libgst/oop.c: Don't pin weak objects to a fixed location.
Expand Down
47 changes: 45 additions & 2 deletions libgst/prims.def
Original file line number Diff line number Diff line change
Expand Up @@ -3073,6 +3073,49 @@ primitive VMpr_String_hash [checks_receiver]
PRIM_SUCCEEDED;
}

/* LargeInteger =
ByteArray =
String =
Array = */
primitive VMpr_ArrayedCollection_equal [succeed,fail]
{
OOP srcOOP, dstOOP;
int dstLen, srcLen;
gst_uchar *dstBase, *srcBase;
_gst_primitives_executed++;

srcOOP = POP_OOP ();
dstOOP = STACKTOP ();
if COMMON (OOP_INT_CLASS (srcOOP) == OOP_INT_CLASS (dstOOP))
{
intptr_t spec = OOP_INSTANCE_SPEC (srcOOP);
if (spec & (~0 << ISP_NUMFIXEDFIELDS))
goto bad;

/* dstEnd is inclusive: (1 to: 1) has length 1 */
dstLen = NUM_INDEXABLE_FIELDS (dstOOP);
srcLen = NUM_INDEXABLE_FIELDS (srcOOP);

if (dstLen != srcLen)
SET_STACKTOP_BOOLEAN (false);
else if UNCOMMON (dstLen == 0)
SET_STACKTOP_BOOLEAN (true);
else
{
/* do the comparison */
dstBase = (gst_uchar *) OOP_TO_OBJ (dstOOP)->data;
srcBase = (gst_uchar *) OOP_TO_OBJ (srcOOP)->data;
dstLen <<= _gst_log2_sizes[spec & ISP_SHAPE];
SET_STACKTOP_BOOLEAN (!memcmp (dstBase, srcBase, dstLen));
}
PRIM_SUCCEEDED;
}

bad:
UNPOP (1);
PRIM_FAILED;
}

/* LargeInteger primReplaceFrom:to:with:startingAt
ByteArray replaceFrom:to:withString:startingAt:
String replaceFrom:to:withByteArray:startingAt:
Expand Down Expand Up @@ -3126,8 +3169,8 @@ primitive VMpr_ArrayedCollection_replaceFromToWithStartingAt [succeed,fail]
if COMMON (dstRangeLen > 0)
{
/* do the copy */
dstBase = STRING_OOP_CHARS (dstOOP);
srcBase = STRING_OOP_CHARS (srcOOP);
dstBase = (gst_uchar *) OOP_TO_OBJ (dstOOP)->data;
srcBase = (gst_uchar *) OOP_TO_OBJ (srcOOP)->data;
dstStartIndex = (dstStartIndex - 1) << size;
srcIndex = (srcIndex - 1) << size;
dstRangeLen <<= size;
Expand Down

0 comments on commit 0f9276d

Please sign in to comment.