Skip to content

Commit

Permalink
Merge pull request #14 from OpenHFT/issue/11
Browse files Browse the repository at this point in the history
Remove deprecated methods, Fix #11
  • Loading branch information
RobAustin authored Mar 25, 2022
2 parents cf770bd + 233330d commit f325120
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
60 changes: 52 additions & 8 deletions src/main/java/net/openhft/chronicle/algo/bytes/Access.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,60 @@ static ReadAccess<RandomDataInput> checkedRandomDataInputAccess() {
return BytesAccesses.RandomDataInputReadAccessEnum.INSTANCE;
}

static <S, T> void copy(ReadAccess<S> sourceAccess, S source, long sourceOffset,
WriteAccess<T> targetAccess, T target, long targetOffset,
long len) {
targetAccess.writeFrom(target, targetOffset, sourceAccess, source, sourceOffset, len);
static <S, T> void copy(final ReadAccess<S> sourceAccess,
final S source,
final long sourceOffset,
final WriteAccess<T> targetAccess,
final T target,
final long targetOffset,
final long len) {
if (targetAccess == sourceAccess && target == source && targetOffset == sourceOffset)
return;
long i = 0;
while (len - i >= 8L) {
targetAccess.writeLong(target, targetOffset + i, sourceAccess.readLong(source, sourceOffset + i));
i += 8L;
}
if (len - i >= 4L) {
targetAccess.writeInt(target, targetOffset + i, sourceAccess.readInt(source, sourceOffset + i));
i += 4L;
}
if (len - i >= 2L) {
targetAccess.writeShort(target, targetOffset + i, sourceAccess.readShort(source, sourceOffset + i));
i += 2L;
}
if (i < len) {
targetAccess.writeByte(target, targetOffset + i, sourceAccess.readByte(source, sourceOffset + i));
}
}

static <T, U> boolean equivalent(ReadAccess<T> access1, T handle1, long offset1,
ReadAccess<U> access2, U handle2, long offset2,
long len) {
return access1.compareTo(handle1, offset1, access2, handle2, offset2, len);
static <T, U> boolean equivalent(final ReadAccess<T> access1,
final T handle1,
final long offset1,
final ReadAccess<U> access2,
final U handle2,
final long offset2,
final long len) {
long i = 0;
while (len - i >= 8L) {
if (access1.readLong(handle1, offset1 + i) != access2.readLong(handle2, offset2 + i))
return false;
i += 8L;
}
if (len - i >= 4L) {
if (access1.readInt(handle1, offset1 + i) != access2.readInt(handle2, offset2 + i))
return false;
i += 4L;
}
if (len - i >= 2L) {
if (access1.readShort(handle1, offset1 + i) != access2.readShort(handle2, offset2 + i))
return false;
i += 2L;
}
if (i < len) {
return access1.readByte(handle1, offset1 + i) == access2.readByte(handle2, offset2 + i);
}
return true;
}

/**
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/net/openhft/chronicle/algo/bytes/ReadAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,30 +88,4 @@ default long readVolatileLong(T handle, long offset) {
throw new UnsupportedOperationException();
}

/**
* @deprecated use {@link Access#equivalent} instead
*/
default <S> boolean compareTo(
T handle, long offset, ReadAccess<S> sourceAccess, S source, long sourceOffset,
long len) {
long i = 0;
while (len - i >= 8L) {
if (readLong(handle, offset + i) != sourceAccess.readLong(source, sourceOffset + i))
return false;
i += 8L;
}
if (len - i >= 4L) {
if (readInt(handle, offset + i) != sourceAccess.readInt(source, sourceOffset + i))
return false;
i += 4L;
}
if (len - i >= 2L) {
if (readShort(handle, offset + i) != sourceAccess.readShort(source, sourceOffset + i))
return false;
i += 2L;
}
if (i < len)
return readByte(handle, offset + i) == sourceAccess.readByte(source, sourceOffset + i);
return true;
}
}
25 changes: 0 additions & 25 deletions src/main/java/net/openhft/chronicle/algo/bytes/WriteAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,31 +69,6 @@ default void writeOrderedLong(T handle, long offset, long i) {

void writeDouble(T handle, long offset, double d);

/**
* @deprecated use {@link Access#copy} instead
*/
default <S> void writeFrom(
T handle, long offset,
ReadAccess<S> sourceAccess, S source, long sourceOffset, long len) {
if (this == sourceAccess && handle == source && offset == sourceOffset)
return;
long i = 0;
while (len - i >= 8L) {
writeLong(handle, offset + i, sourceAccess.readLong(source, sourceOffset + i));
i += 8L;
}
if (len - i >= 4L) {
writeInt(handle, offset + i, sourceAccess.readInt(source, sourceOffset + i));
i += 4L;
}
if (len - i >= 2L) {
writeShort(handle, offset + i, sourceAccess.readShort(source, sourceOffset + i));
i += 2L;
}
if (i < len)
writeByte(handle, offset + i, sourceAccess.readByte(source, sourceOffset + i));
}

default void writeBytes(T handle, long offset, long len, byte b) {
char c;
int i;
Expand Down

0 comments on commit f325120

Please sign in to comment.