From bad85fb879f9a9621335d1229bbca847cac8466a Mon Sep 17 00:00:00 2001 From: Jonathan Frederic Date: Thu, 16 Jan 2014 11:53:22 +0000 Subject: [PATCH] Remove O(N) cell by msg-id lookup --- IPython/html/static/notebook/js/codecell.js | 6 ++++++ IPython/html/static/notebook/js/notebook.js | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/IPython/html/static/notebook/js/codecell.js b/IPython/html/static/notebook/js/codecell.js index d5b05d6e1..6ff3bec74 100644 --- a/IPython/html/static/notebook/js/codecell.js +++ b/IPython/html/static/notebook/js/codecell.js @@ -105,6 +105,7 @@ var IPython = (function (IPython) { } }; + CodeCell.msg_cells = {}; CodeCell.prototype = new IPython.Cell(); @@ -317,7 +318,12 @@ var IPython = (function (IPython) { } var callbacks = this.get_callbacks(); + var old_msg_id = this.last_msg_id; this.last_msg_id = this.kernel.execute(this.get_text(), callbacks, {silent: false, store_history: true}); + if (old_msg_id) { + delete CodeCell.msg_cells[old_msg_id]; + } + CodeCell.msg_cells[this.last_msg_id] = this; }; /** diff --git a/IPython/html/static/notebook/js/notebook.js b/IPython/html/static/notebook/js/notebook.js index 11c9a1d4e..9abf8db6c 100644 --- a/IPython/html/static/notebook/js/notebook.js +++ b/IPython/html/static/notebook/js/notebook.js @@ -308,12 +308,8 @@ var IPython = (function (IPython) { * @return {Cell} Cell or null if no cell was found. */ Notebook.prototype.get_msg_cell = function (msg_id) { - var cells = this.get_cells(); - for (var cell_index in cells) { - if (cells[cell_index].last_msg_id == msg_id) { - var cell = this.get_cell(cell_index) - return cell; - } + if (IPython.CodeCell.msg_cells[msg_id] !== undefined) { + return IPython.CodeCell.msg_cells[msg_id]; } return null; };