adium 2756:0c12378de034: Reduce some duplicate code here.
commits at adium.im
commits at adium.im
Wed Oct 21 14:30:13 UTC 2009
details: http://hg.adium.im/adium/rev/0c12378de034
revision: 2756:0c12378de034
author: Stephen Holt <sholt at adium.im>
date: Wed Oct 21 10:29:31 2009 -0400
Reduce some duplicate code here.
Subject: adium 2757:ea5902712400: Comments are nice. I like comments.
details: http://hg.adium.im/adium/rev/ea5902712400
revision: 2757:ea5902712400
author: Stephen Holt <sholt at adium.im>
date: Wed Oct 21 10:29:32 2009 -0400
Comments are nice. I like comments.
Subject: adium 2758:1baad7856ddd: Set temporary objects to null after we're not using them.
details: http://hg.adium.im/adium/rev/1baad7856ddd
revision: 2758:1baad7856ddd
author: Stephen Holt <sholt at adium.im>
date: Wed Oct 21 10:29:33 2009 -0400
Set temporary objects to null after we're not using them.
We shouldn't need this, but it's cheap and ensures extra DOM elements get collected.
diffs (106 lines):
diff -r 48e20ed6580f -r 1baad7856ddd Plugins/WebKit Message View/Template.html
--- a/Plugins/WebKit Message View/Template.html Tue Oct 20 23:07:17 2009 -0400
+++ b/Plugins/WebKit Message View/Template.html Wed Oct 21 10:29:33 2009 -0400
@@ -42,11 +42,14 @@
alignChat(self.shouldScroll);
// reset state to empty/non-coalescing
+ documentFragment = null;
self.shouldScroll = false;
self.isCoalescing = false;
self.coalesceRounds = 0;
}
+ // creates and returns a new documentFragment, containing all content nodes
+ // which can be inserted as a single node.
function createHTMLNode(html) {
var newMessage = document.createElement("div");
var documentFragment = document.createDocumentFragment();
@@ -59,6 +62,19 @@
return documentFragment;
}
+ // removes first insert node from the internal fragment.
+ function rmInsertNode() {
+ var insert = self.fragment.querySelector("#insert");
+ if(insert)
+ insert.parentNode.removeChild(insert);
+ }
+
+ // (re)start the coalescing timer.
+ // we wait 10ms for a new message to come in.
+ // If we get one, restart the timer and wait another 10ms.
+ // If not, run outputHTML()
+ // We do this a maximum of 500 times, for 5s max that can be spent
+ // coalescing input, since this will block display.
this.coalesce = function() {
window.clearTimeout(self.timeoutID);
self.timeoutID = window.setTimeout(outputHTML, 10);
@@ -77,13 +93,15 @@
}
}
+
+ // coalased analogs to the global functions
+
this.append = function(html, shouldScroll) {
+ rmInsertNode();
var node = createHTMLNode(html);
- var insert = self.fragment.querySelector("#insert");
- if(insert) {
- insert.parentNode.removeChild(insert);
- }
self.fragment.appendChild(node);
+
+ node = null;
if(shouldScroll) self.shouldScroll = shouldScroll;
self.coalesce();
@@ -94,6 +112,8 @@
if(insert) {
var node = createHTMLNode(html);
insert.parentNode.replaceChild(node, insert);
+
+ node = null;
} else {
self.append(html, shouldScroll);
}
@@ -103,12 +123,11 @@
}
this.replaceLast = function (html, shouldScroll) {
+ rmInsertNode();
var node = createHTMLNode(html);
- var insert = self.fragment.querySelector("#insert");
- if(insert)
- insert.parentNode.removeChild(insert);
var lastMessage = self.fragment.lastChild;
lastMessage.parentNode.replaceChild(node, lastMessage);
+ node = null;
if(shouldScroll)
self.shouldScroll = shouldScroll;
}
@@ -123,6 +142,7 @@
function appendMessageNoScroll(html, shouldScroll) {
shouldScroll = shouldScroll || false;
+ // always try to coalesce new, non-griuped, messages
coalescedHTML.append(html, shouldScroll)
}
@@ -133,6 +153,7 @@
function appendNextMessageNoScroll(html, shouldScroll){
shouldScroll = shouldScroll || false;
+ // only group next messages if we're already coalescing input
if(coalescedHTML.isCoalescing){
coalescedHTML.appendNext(html, shouldScroll);
} else {
@@ -155,6 +176,7 @@
function replaceLastMessage(html){
shouldScroll = nearBottom();
+ // only replace messages if we're already coalescing
if(coalescedHTML.isCoalescing){
coalescedHTML.replaceLast(html, shouldScroll);
} else {
More information about the commits
mailing list