1251 OBJ cls; |
1278 OBJ cls; |
1252 |
1279 |
1253 if (__isSmallInteger(aNumber) |
1280 if (__isSmallInteger(aNumber) |
1254 && __bothSmallInteger(start, stop) |
1281 && __bothSmallInteger(start, stop) |
1255 && __isBytes(self)) { |
1282 && __isBytes(self)) { |
1256 len = __byteArraySize(self); |
1283 len = __byteArraySize(self); |
1257 index1 = __intVal(start); |
1284 index1 = __intVal(start); |
1258 index2 = __intVal(stop); |
1285 index2 = __intVal(stop); |
1259 |
1286 |
1260 dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1; |
1287 dstp = __ByteArrayInstPtr(self)->ba_element + index1 - 1; |
1261 if ((cls = __qClass(self)) != @global(ByteArray)) { |
1288 if ((cls = __qClass(self)) != @global(ByteArray)) { |
1262 int nInst; |
1289 int nInst; |
1263 |
1290 |
1264 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1291 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1265 dstp += nInst; |
1292 dstp += nInst; |
1266 len -= nInst; |
1293 len -= nInst; |
1267 } |
1294 } |
1268 |
1295 |
1269 value = __intVal(aNumber); |
1296 value = __intVal(aNumber); |
1270 if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */ |
1297 if (((unsigned)value <= 0xFF) /* i.e. (value >= 0) && (value <= 255) */ |
1271 && (index1 <= index2) |
1298 && (index1 <= index2) |
1272 && (index1 > 0)) { |
1299 && (index1 > 0)) { |
1273 if (index2 <= len) { |
1300 if (index2 <= len) { |
1274 count = index2 - index1 + 1; |
1301 count = index2 - index1 + 1; |
1275 |
1302 |
1276 #ifdef memset4 |
1303 #ifdef memset4 |
1277 if (count > 20) { |
1304 if (count > 20) { |
1278 while (((unsigned INT)dstp & 3) != 0) { |
1305 /* fill unaligned part */ |
1279 *dstp++ = value; |
1306 while (((unsigned INT)dstp & 3) != 0) { |
1280 count--; |
1307 *dstp++ = value; |
1281 } |
1308 count--; |
1282 { |
1309 } |
1283 int n4 = count & ~3; |
1310 /* fill aligned part */ |
1284 int v4, nW; |
1311 { |
1285 |
1312 int n4 = count & ~3; |
1286 v4 = (value << 8) | value; |
1313 int v4, nW; |
1287 v4 = (v4 << 16) | v4; |
1314 |
1288 nW = n4>>2; |
1315 v4 = (value << 8) | value; |
1289 memset4(dstp, v4, nW); |
1316 v4 = (v4 << 16) | v4; |
1290 count -= n4; |
1317 nW = n4>>2; |
1291 dstp += n4; |
1318 memset4(dstp, v4, nW); |
1292 } |
1319 count -= n4; |
1293 while (count--) { |
1320 dstp += n4; |
1294 *dstp++ = value; |
1321 } |
1295 } |
1322 while (count--) { |
1296 RETURN (self); |
1323 *dstp++ = value; |
1297 } |
1324 } |
|
1325 RETURN (self); |
|
1326 } |
1298 #endif /* memset4 */ |
1327 #endif /* memset4 */ |
1299 |
1328 |
1300 #ifdef FAST_MEMSET |
1329 #ifdef FAST_MEMSET |
1301 memset(dstp, value, count); |
1330 memset(dstp, value, count); |
1302 #else |
1331 #else |
1303 # ifdef UNROLL_LOOPS |
1332 # ifdef UNROLL_LOOPS |
1304 while (count >= 8) { |
1333 while (count >= 8) { |
1305 dstp[0] = dstp[1] = dstp[2] = dstp[3] = |
1334 dstp[0] = dstp[1] = dstp[2] = dstp[3] = |
1306 dstp[4] = dstp[5] = dstp[6] = dstp[7] = value; |
1335 dstp[4] = dstp[5] = dstp[6] = dstp[7] = value; |
1307 dstp += 8; |
1336 dstp += 8; |
1308 count -= 8; |
1337 count -= 8; |
1309 } |
1338 } |
1310 # endif /* UNROLL_LOOPS */ |
1339 # endif /* UNROLL_LOOPS */ |
1311 while (count--) { |
1340 while (count--) { |
1312 *dstp++ = value; |
1341 *dstp++ = value; |
1313 } |
1342 } |
1314 #endif |
1343 #endif |
1315 RETURN (self); |
1344 RETURN (self); |
1316 } |
1345 } |
1317 } |
1346 } |
1318 } |
1347 } |
1319 %}. |
1348 %}. |
1320 " |
1349 " |
1321 fall back in case of non-integer index or out-of-bound index/value; |
1350 fall back in case of non-integer index or out-of-bound index/value; |
1322 will eventually lead to an out-of-bound signal raise |
1351 will eventually lead to an out-of-bound signal raise |
1344 #ifndef NO_PRIM_BYTEARR |
1373 #ifndef NO_PRIM_BYTEARR |
1345 if (__isBytes(aCollection) |
1374 if (__isBytes(aCollection) |
1346 && __isBytes(self) |
1375 && __isBytes(self) |
1347 && __bothSmallInteger(start, stop) |
1376 && __bothSmallInteger(start, stop) |
1348 && __isSmallInteger(repStart)) { |
1377 && __isSmallInteger(repStart)) { |
1349 startIndex = __intVal(start) - 1; |
1378 startIndex = __intVal(start) - 1; |
1350 if (startIndex >= 0) { |
1379 if (startIndex >= 0) { |
1351 dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex; |
1380 dst = (__ByteArrayInstPtr(self)->ba_element) + startIndex; |
1352 nIndex = __byteArraySize(self); |
1381 nIndex = __byteArraySize(self); |
1353 |
1382 |
1354 if ((cls = __qClass(self)) != @global(ByteArray)) { |
1383 if ((cls = __qClass(self)) != @global(ByteArray)) { |
1355 int nInst; |
1384 int nInst; |
1356 |
1385 |
1357 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1386 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1358 dst += nInst; |
1387 dst += nInst; |
1359 nIndex -= nInst; |
1388 nIndex -= nInst; |
1360 } |
1389 } |
1361 |
1390 |
1362 stopIndex = __intVal(stop) - 1; |
1391 stopIndex = __intVal(stop) - 1; |
1363 count = stopIndex - startIndex + 1; |
1392 count = stopIndex - startIndex + 1; |
1364 if (count == 0) { |
1393 if (count == 0) { |
1365 RETURN ( self ); |
1394 RETURN ( self ); |
1366 } |
1395 } |
1367 |
1396 |
1368 if ((count > 0) && (stopIndex < nIndex)) { |
1397 if ((count > 0) && (stopIndex < nIndex)) { |
1369 repStartIndex = __intVal(repStart) - 1; |
1398 repStartIndex = __intVal(repStart) - 1; |
1370 if (repStartIndex >= 0) { |
1399 if (repStartIndex >= 0) { |
1371 repNIndex = __qSize(aCollection) - OHDR_SIZE; |
1400 repNIndex = __qSize(aCollection) - OHDR_SIZE; |
1372 src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex; |
1401 src = (__ByteArrayInstPtr(aCollection)->ba_element) + repStartIndex; |
1373 if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
1402 if ((cls = __qClass(aCollection)) != @global(ByteArray)) { |
1374 int nInst; |
1403 int nInst; |
1375 |
1404 |
1376 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1405 nInst = __OBJS2BYTES__(__intVal(__ClassInstPtr(cls)->c_ninstvars)); |
1377 src += nInst; |
1406 src += nInst; |
1378 repNIndex -= nInst; |
1407 repNIndex -= nInst; |
1379 } |
1408 } |
1380 |
1409 |
1381 repStopIndex = repStartIndex + (stopIndex - startIndex); |
1410 repStopIndex = repStartIndex + (stopIndex - startIndex); |
1382 if (repStopIndex < repNIndex) { |
1411 if (repStopIndex < repNIndex) { |
1383 if (aCollection == self) { |
1412 if (aCollection == self) { |
1384 /* take care of overlapping copy */ |
1413 /* take care of overlapping copy */ |
1385 if (src < dst) { |
1414 if (src < dst) { |
1386 /* must do a reverse copy */ |
1415 /* must do a reverse copy */ |
1387 src += count; |
1416 src += count; |
1388 dst += count; |
1417 dst += count; |
1389 while (count-- > 0) { |
1418 while (count-- > 0) { |
1390 *--dst = *--src; |
1419 *--dst = *--src; |
1391 } |
1420 } |
1392 RETURN ( self ); |
1421 RETURN ( self ); |
1393 } |
1422 } |
1394 } |
1423 } |
1395 |
1424 |
1396 #ifdef bcopy4 |
1425 #ifdef bcopy4 |
1397 if ((((unsigned INT)src & 3) == 0) |
1426 if (((unsigned INT)src & 3) == ((unsigned INT)dst & 3)) { |
1398 && (((unsigned INT)dst & 3) == 0)) { |
1427 int nW; |
1399 /* copy aligned part */ |
1428 |
1400 int nW = count >> 2; |
1429 /* copy unaligned part */ |
1401 |
1430 while (count && ((unsigned INT)src & 3)) { |
1402 bcopy4(src, dst, nW); |
1431 *dst++ = *src++; |
1403 if ((count = count & 3) != 0) { |
1432 count--; |
1404 /* copy any remaining part */ |
1433 } |
1405 src += (nW<<2); |
1434 |
1406 dst += (nW<<2); |
1435 if (count > 0) { |
1407 while (count--) { |
1436 /* copy aligned part */ |
1408 *dst++ = *src++; |
1437 nW = count >> 2; |
1409 } |
1438 bcopy4(src, dst, nW); |
1410 } |
1439 if ((count = count & 3) != 0) { |
1411 RETURN ( self ); |
1440 /* copy any remaining part */ |
1412 } |
1441 src += (nW<<2); |
|
1442 dst += (nW<<2); |
|
1443 while (count--) { |
|
1444 *dst++ = *src++; |
|
1445 } |
|
1446 } |
|
1447 } |
|
1448 RETURN ( self ); |
|
1449 } |
1413 #else |
1450 #else |
1414 # ifdef alpha64 |
1451 # ifdef alpha64 |
1415 if ((((unsigned INT)src & 7) == 0) |
1452 if (((unsigned INT)src & 7) == ((unsigned INT)dst & 7)) { |
1416 && (((unsigned INT)dst & 7) == 0)) { |
1453 /* copy unaligned part */ |
1417 /* copy aligned part */ |
1454 while (count && ((unsigned INT)src & 7)) { |
1418 int nW = count >> 3; |
1455 *dst++ = *src++; |
1419 |
1456 count--; |
1420 while (count >= 8) { |
1457 } |
1421 ((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
1458 |
1422 dst += 8; |
1459 /* copy aligned part */ |
1423 src += 8; |
1460 while (count >= 8) { |
1424 count -= 8; |
1461 ((unsigned INT *)dst)[0] = ((unsigned INT *)src)[0]; |
1425 } |
1462 dst += 8; |
1426 while (count--) { |
1463 src += 8; |
1427 *dst++ = *src++; |
1464 count -= 8; |
1428 } |
1465 } |
1429 RETURN ( self ); |
1466 while (count--) { |
1430 } |
1467 *dst++ = *src++; |
|
1468 } |
|
1469 RETURN ( self ); |
|
1470 } |
1431 # endif /* alpha64 */ |
1471 # endif /* alpha64 */ |
1432 #endif /* bcopy4 */ |
1472 #endif /* bcopy4 */ |
1433 |
1473 |
1434 #ifdef FAST_MEMCPY |
1474 #ifdef FAST_MEMCPY |
1435 bcopy(src, dst, count); |
1475 bcopy(src, dst, count); |
1436 #else |
1476 #else |
1437 # ifdef UNROLL_LOOPS |
1477 # ifdef UNROLL_LOOPS |
1438 while (count >= 8) { |
1478 while (count >= 8) { |
1439 dst[0] = src[0]; dst[1] = src[1]; |
1479 dst[0] = src[0]; dst[1] = src[1]; |
1440 dst[2] = src[2]; dst[3] = src[3]; |
1480 dst[2] = src[2]; dst[3] = src[3]; |
1441 dst[4] = src[4]; dst[5] = src[5]; |
1481 dst[4] = src[4]; dst[5] = src[5]; |
1442 dst[6] = src[6]; dst[7] = src[7]; |
1482 dst[6] = src[6]; dst[7] = src[7]; |
1443 dst += 8; src += 8; |
1483 dst += 8; src += 8; |
1444 count -= 8; |
1484 count -= 8; |
1445 } |
1485 } |
1446 # endif /* UNROLL_LOOPS */ |
1486 # endif /* UNROLL_LOOPS */ |
1447 while (count-- > 0) { |
1487 while (count-- > 0) { |
1448 *dst++ = *src++; |
1488 *dst++ = *src++; |
1449 } |
1489 } |
1450 #endif |
1490 #endif |
1451 RETURN ( self ); |
1491 RETURN ( self ); |
1452 } |
1492 } |
1453 } |
1493 } |
1454 } |
1494 } |
1455 } |
1495 } |
1456 } |
1496 } |
1457 #endif |
1497 #endif |
1458 %}. |
1498 %}. |
1459 " |
1499 " |
1460 fall back in case of non-ByteArray argument, |
1500 fall back in case of non-ByteArray argument, |
1461 or for the error report if any index is invalid |
1501 or for the error report if any index is invalid |
1462 " |
1502 " |
1463 ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
1503 ^ super replaceFrom:start to:stop with:aCollection startingAt:repStart |
|
1504 |
|
1505 " |
|
1506 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
|
1507 copy |
|
1508 replaceFrom:1 to:8 |
|
1509 with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1510 startingAt:1 |
|
1511 |
|
1512 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
|
1513 copy |
|
1514 replaceFrom:3 to:10 |
|
1515 with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1516 startingAt:1 |
|
1517 |
|
1518 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
|
1519 copy |
|
1520 replaceFrom:3 to:4 |
|
1521 with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1522 startingAt:1 |
|
1523 |
|
1524 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
|
1525 copy |
|
1526 replaceFrom:0 to:9 |
|
1527 with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1528 startingAt:1 |
|
1529 |
|
1530 #[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16] |
|
1531 copy |
|
1532 replaceFrom:1 to:10 |
|
1533 with:#[10 20 30 40 50 60 70 80 90 100 110 120 130 140 150 160] |
|
1534 startingAt:0 |
|
1535 " |
1464 ! |
1536 ! |
1465 |
1537 |
1466 replaceBytesFrom:startIndex with:replacementCollection startingAt:repStartIndex |
1538 replaceBytesFrom:startIndex with:replacementCollection startingAt:repStartIndex |
1467 "replace elements from another collection, which must be |
1539 "replace elements from another collection, which must be |
1468 byte-array-like. |
1540 byte-array-like. |