Mercurial > hg > octave-nkf
annotate src/pt-cell.cc @ 8588:79845b1793cf
optimize cell construction from a cs-list
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 25 Jan 2009 08:04:56 +0100 |
parents | 71f068b22fcc |
children | 73c4516fae10 |
rev | line source |
---|---|
3353 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 |
4 John W. Eaton | |
3353 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
3353 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
3353 | 21 |
22 */ | |
23 | |
24 #ifdef HAVE_CONFIG_H | |
25 #include <config.h> | |
26 #endif | |
27 | |
3503 | 28 #include <iostream> |
3353 | 29 |
30 #include "Cell.h" | |
31 #include "defun.h" | |
32 #include "error.h" | |
33 #include "oct-obj.h" | |
34 #include "pt-arg-list.h" | |
3770 | 35 #include "pt-bp.h" |
3353 | 36 #include "pt-exp.h" |
37 #include "pt-cell.h" | |
38 #include "pt-walk.h" | |
39 #include "utils.h" | |
40 #include "ov.h" | |
41 #include "variables.h" | |
42 | |
43 octave_value | |
44 tree_cell::rvalue (void) | |
45 { | |
46 octave_value retval; | |
47 | |
3770 | 48 MAYBE_DO_BREAKPOINT; |
49 | |
5275 | 50 octave_idx_type nr = length (); |
51 octave_idx_type nc = -1; | |
3353 | 52 |
4501 | 53 Cell val; |
3353 | 54 |
55 int i = 0; | |
56 | |
4219 | 57 for (iterator p = begin (); p != end (); p++) |
3353 | 58 { |
4219 | 59 tree_argument_list *elt = *p; |
3353 | 60 |
61 octave_value_list row = elt->convert_to_const_vector (); | |
62 | |
8588
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
63 if (nr == 1) |
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
64 // Optimize the single row case. |
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
65 val = row.cell_value (); |
79845b1793cf
optimize cell construction from a cs-list
Jaroslav Hajek <highegg@gmail.com>
parents:
7767
diff
changeset
|
66 else if (nc < 0) |
4501 | 67 { |
68 nc = row.length (); | |
69 | |
70 val = Cell (nr, nc); | |
71 } | |
72 else | |
73 { | |
5275 | 74 octave_idx_type this_nc = row.length (); |
4501 | 75 |
76 if (nc != this_nc) | |
77 { | |
78 ::error ("number of columns must match"); | |
79 return retval; | |
80 } | |
81 } | |
82 | |
5275 | 83 for (octave_idx_type j = 0; j < nc; j++) |
3353 | 84 val(i,j) = row(j); |
85 | |
86 i++; | |
87 } | |
88 | |
89 retval = val; | |
90 | |
91 return retval; | |
92 } | |
93 | |
3556 | 94 octave_value_list |
95 tree_cell::rvalue (int nargout) | |
96 { | |
97 octave_value_list retval; | |
98 | |
99 if (nargout > 1) | |
100 error ("invalid number of output arguments for cell array"); | |
101 else | |
102 retval = rvalue (); | |
103 | |
104 return retval; | |
105 } | |
106 | |
5861 | 107 tree_expression * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
108 tree_cell::dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
109 symbol_table::context_id context) |
5861 | 110 { |
111 tree_cell *new_cell = new tree_cell (0, line (), column ()); | |
112 | |
113 for (iterator p = begin (); p != end (); p++) | |
114 { | |
115 tree_argument_list *elt = *p; | |
116 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7336
diff
changeset
|
117 new_cell->append (elt ? elt->dup (scope, context) : 0); |
5861 | 118 } |
119 | |
120 new_cell->copy_base (*this); | |
121 | |
122 return new_cell; | |
123 } | |
124 | |
3353 | 125 void |
126 tree_cell::accept (tree_walker& tw) | |
127 { | |
128 tw.visit_cell (*this); | |
129 } | |
130 | |
131 /* | |
132 ;;; Local Variables: *** | |
133 ;;; mode: C++ *** | |
134 ;;; End: *** | |
135 */ |