Remove O(N) cell by msg-id lookup

This commit is contained in:
Jonathan Frederic 2014-01-16 11:53:22 +00:00
parent ff39989b8b
commit bad85fb879
2 changed files with 8 additions and 6 deletions

View File

@ -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;
};
/**

View File

@ -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;
};