Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: avoid regex split on chat message #638

Merged
merged 4 commits into from Sep 4, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions chat/src/main/java/com/github/twitch4j/chat/TwitchChat.java
Expand Up @@ -530,8 +530,7 @@ protected void onConnected() {
}

protected void onTextMessage(String text) {
Arrays.asList(text.replace("\n\r", "\n")
.replace("\r", "\n").split("\n"))
Arrays.asList(StringUtils.split(text.replace("\r\n", "\n"), '\n'))
.forEach(message -> {
if (!message.equals("")) {
// Handle messages
Expand Down Expand Up @@ -761,6 +760,11 @@ private boolean removeCurrentChannel(String channelName) {
@Override
@SuppressWarnings("ConstantConditions")
public boolean sendMessage(String channel, String message, Map<String, Object> tags) {
if (message.length() > 500) {
PhilippHeuer marked this conversation as resolved.
Show resolved Hide resolved
log.warn("Ignoring outbound chat message for channel #{} exceeding the Twitch maximum of 500 characters: {}", channel, message);
return false;
}

StringBuilder sb = new StringBuilder();
if (tags != null && !tags.isEmpty()) {
sb.append('@');
Expand Down