Improve StringByteString performance

This commit is contained in:
DBotThePony 2024-04-18 14:09:44 +07:00
parent 3ead24267c
commit adab78f0c0
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 7 additions and 1 deletions
luna/src/main/java/org/classdump/luna
src/main/kotlin/ru/dbotthepony/kstarbound/lua

View File

@ -64,6 +64,10 @@ class StringByteString extends ByteString {
return true; return true;
} }
if (that instanceof StringByteString tstring) {
return string.equals(tstring.string);
}
// don't force hashCode computation, but use if already known // don't force hashCode computation, but use if already known
int thisHash = this.maybeHashCode(); int thisHash = this.maybeHashCode();
int thatHash = that.maybeHashCode(); int thatHash = that.maybeHashCode();

View File

@ -230,9 +230,11 @@ private object JsonTableIndex : AbstractFunction3<Table, Any, Any?>() {
throw NonsuspendableFunctionException(this::class.java) throw NonsuspendableFunctionException(this::class.java)
} }
private val __nils: ByteString = ByteString.of("__nils")
override fun invoke(context: ExecutionContext, self: Table, key: Any, value: Any?) { override fun invoke(context: ExecutionContext, self: Table, key: Any, value: Any?) {
val meta = self.metatable val meta = self.metatable
val nils = meta["__nils"] as Table val nils = meta[__nils] as Table
// If we are setting an entry to nil, need to add a bogus integer entry // If we are setting an entry to nil, need to add a bogus integer entry
// to the __nils table, otherwise need to set the entry *in* the __nils // to the __nils table, otherwise need to set the entry *in* the __nils