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

Get rid of double indirection #536

Open
marton78 opened this issue Dec 19, 2024 · 2 comments
Open

Get rid of double indirection #536

marton78 opened this issue Dec 19, 2024 · 2 comments

Comments

@marton78
Copy link

Hi, first of all thanks for this great library.

One hint: you could get rid of the double indirection in

using OnMessageCallback = std::function<void(const WebSocketMessagePtr&)>;

by changing it to

using OnMessageCallback = std::function<void(const WebSocketMessage&)>;

This could also be done in a backwards-compatible fashion by offering a second overload, e.g.:

using OnMessageCallbackNew = std::function<void(const WebSocketMessage&)>;
void setOnMessageCallback(const OnMessageCallbackNew& callback);
@marton78
Copy link
Author

PS: I just saw that WebSocketMessage contains a const std::string& str, that's QUADRUPLE indirection (a pointer to the string, and therein a pointer to the string's contents).

@bsergean
Copy link
Collaborator

Did you try to change to

using OnMessageCallback = std::function<void(const WebSocketMessage&)>;

What I do remember is trying real hard to avoid all thread races. But I might have tried a pointer for speedup, which could have been a bad idea.

I had written something called autoroute which was meant to be a benchmark -> https://github.com/bsergean/autoroute
it would be nice to bench your new solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants