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

Small perf change. See commits for details. #24

Merged
merged 2 commits into from
Sep 27, 2011
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.URI;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ final class IdleConnectionQueue {

final TimeoutResolver resolver = new TimeoutResolver();
final long timeout;
final AtomicInteger count = new AtomicInteger(0);

// ---------------------------------------------------- Constructors

Expand All @@ -377,9 +378,11 @@ void offer(final Connection c) {
resolver.setTimeoutMs(c, System.currentTimeMillis() + timeout);
}
queue.offer(c);
count.incrementAndGet();
}

Connection poll() {
count.decrementAndGet();
return queue.poll();
}

Expand All @@ -388,15 +391,16 @@ boolean remove(final Connection c) {
resolver.removeTimeout(c);

}
count.decrementAndGet();
return queue.remove(c);
}

int size() {
return queue.size();
return count.get();
}

boolean isEmpty() {
return queue.isEmpty();
return (count.get() == 0);
}

void destroy() {
Expand Down