Skip to content

Commit

Permalink
squash: Do not create multiple times the parser on hotter paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
damencho committed Oct 31, 2024
1 parent 54b5966 commit 19f9bca
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/main/java/org/jitsi/jigasi/AudioModeration.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,8 @@ private IQ handleMuteIq(MuteIq muteIq)
private class AVModerationListener
implements StanzaListener
{
private JSONParser parser = new JSONParser();

@Override
public void processStanza(Stanza packet)
{
Expand All @@ -627,7 +629,7 @@ public void processStanza(Stanza packet)

try
{
Object o = new JSONParser().parse(jsonMsg.getJson());
Object o = parser.parse(jsonMsg.getJson());

if (o instanceof JSONObject)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ public class VoskTranscriptionService
*/
private String websocketUrl;

private final JSONParser jsonParser = new JSONParser();

/**
* Assigns the websocketUrl to use to websocketUrl by reading websocketUrlConfig;
*/
Expand Down Expand Up @@ -281,7 +283,7 @@ private void onMessageInternal(String msg)

boolean partial = true;
String result = "";
JSONObject obj = (JSONObject)new JSONParser().parse(msg);
JSONObject obj = (JSONObject)jsonParser.parse(msg);
if (obj.containsKey("partial"))
{
result = (String)obj.get("partial");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ public class WhisperWebsocket
*/
private static final ExecutorService threadPool = Util.createNewThreadPool("jigasi-whisper-ws");

private final JSONParser jsonParser = new JSONParser();

/**
* Creates a connection url by concatenating the websocket
* url with the Connection Id;
Expand Down Expand Up @@ -318,7 +320,7 @@ private void onMessageInternal(String msg)
boolean partial = true;
String result;

JSONObject obj = (JSONObject)new JSONParser().parse(msg);
JSONObject obj = (JSONObject)jsonParser.parse(msg);
String msgType = (String)obj.get("type");
String participantId = (String)obj.get("participant_id");
Participant participant = participants.get(participantId);
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/jitsi/jigasi/visitor/WebsocketClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ public class WebsocketClient
*/
private ScheduledFuture ponger;

private final JSONParser jsonParser = new JSONParser();

/**
* A timer which will be used to schedule connection to conference after going live.
*/
Expand Down Expand Up @@ -371,7 +373,7 @@ else if (command.equals("MESSAGE"))
{
try
{
Object o = new JSONParser().parse(body.replace(END, ""));
Object o = jsonParser.parse(body.replace(END, ""));

if (o instanceof JSONObject)
{
Expand Down

0 comments on commit 19f9bca

Please sign in to comment.