Reduces JC usage by creating arrays with the exact amount of bytes when deserializing events.
This commit is contained in:
@@ -272,13 +272,14 @@ open class Event(
|
|||||||
private class GossipDeserializer : StdDeserializer<Gossip>(Gossip::class.java) {
|
private class GossipDeserializer : StdDeserializer<Gossip>(Gossip::class.java) {
|
||||||
override fun deserialize(jp: JsonParser, ctxt: DeserializationContext): Gossip {
|
override fun deserialize(jp: JsonParser, ctxt: DeserializationContext): Gossip {
|
||||||
val jsonObject: JsonNode = jp.codec.readTree(jp)
|
val jsonObject: JsonNode = jp.codec.readTree(jp)
|
||||||
|
val tagList = jsonObject.get("tags")
|
||||||
return Gossip(
|
return Gossip(
|
||||||
id = jsonObject.get("id")?.asText()?.intern(),
|
id = jsonObject.get("id")?.asText()?.intern(),
|
||||||
pubKey = jsonObject.get("pubkey")?.asText()?.intern(),
|
pubKey = jsonObject.get("pubkey")?.asText()?.intern(),
|
||||||
createdAt = jsonObject.get("created_at")?.asLong(),
|
createdAt = jsonObject.get("created_at")?.asLong(),
|
||||||
kind = jsonObject.get("kind")?.asInt(),
|
kind = jsonObject.get("kind")?.asInt(),
|
||||||
tags = jsonObject.get("tags")?.map {
|
tags = tagList.mapTo(ArrayList<List<String>>(tagList.size())) {
|
||||||
it.mapNotNull { s -> if (s?.isNull ?: true) null else s.asText().intern() }
|
it.mapNotNullTo(ArrayList<String>(it.size())) { s -> if (s.isNull) null else s.asText().intern() }
|
||||||
},
|
},
|
||||||
content = jsonObject.get("content")?.asText()
|
content = jsonObject.get("content")?.asText()
|
||||||
)
|
)
|
||||||
@@ -360,13 +361,14 @@ open class Event(
|
|||||||
)
|
)
|
||||||
|
|
||||||
fun fromJson(jsonObject: JsonNode): Event {
|
fun fromJson(jsonObject: JsonNode): Event {
|
||||||
|
val tagList = jsonObject.get("tags")
|
||||||
return EventFactory.create(
|
return EventFactory.create(
|
||||||
id = jsonObject.get("id").asText().intern(),
|
id = jsonObject.get("id").asText().intern(),
|
||||||
pubKey = jsonObject.get("pubkey").asText().intern(),
|
pubKey = jsonObject.get("pubkey").asText().intern(),
|
||||||
createdAt = jsonObject.get("created_at").asLong(),
|
createdAt = jsonObject.get("created_at").asLong(),
|
||||||
kind = jsonObject.get("kind").asInt(),
|
kind = jsonObject.get("kind").asInt(),
|
||||||
tags = jsonObject.get("tags").map {
|
tags = tagList.mapTo(ArrayList<List<String>>(tagList.size())) {
|
||||||
it.mapNotNull { s -> if (s.isNull) null else s.asText().intern() }
|
it.mapNotNullTo(ArrayList<String>(it.size())) { s -> if (s.isNull) null else s.asText().intern() }
|
||||||
},
|
},
|
||||||
content = jsonObject.get("content").asText(),
|
content = jsonObject.get("content").asText(),
|
||||||
sig = jsonObject.get("sig").asText()
|
sig = jsonObject.get("sig").asText()
|
||||||
|
|||||||
Reference in New Issue
Block a user