Skip to content

Commit 4cb305e

Browse files
Marc-Oliver GewaltigMarc-Oliver Gewaltig
authored andcommitted
Names are now pased by references and this improves performancs.
1 parent 3eea7f6 commit 4cb305e

9 files changed

+120
-122
lines changed

sli_builtins.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,25 @@ void IforFunction::execute(SLIInterpreter *i) const
236236
i->push(t);
237237
}
238238

239-
240239
long &count=i->EStack().pick(3).data_.long_val;
241240
long &lim=i->EStack().pick(4).data_.long_val;
242241
long &inc=i->EStack().pick(5).data_.long_val;
243242

244-
if(( (inc> 0) && (count <= lim)) ||
245-
( (inc< 0) && (count >= lim)))
246-
{
247-
pos=0; // reset procedure interator
248-
249-
i->push(i->EStack().pick(3)); // push counter to user
250-
count += inc; // increment loop counter
243+
if(( (inc> 0) && (count <= lim)) ||
244+
( (inc< 0) && (count >= lim)))
245+
{
246+
pos=0; // reset procedure interator
247+
248+
i->push(i->EStack().pick(3)); // push counter to user
249+
count += inc; // increment loop counter
251250
}
252-
else
251+
else
253252
{
254-
i->EStack().pop(7);
255-
i->dec_call_depth();
253+
i->EStack().pop(7);
254+
i->dec_call_depth();
256255
}
257256
}
258-
257+
259258
void IforFunction::backtrace(SLIInterpreter *i, int p) const
260259
{
261260
/*

sli_control.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,15 @@ void IfFunction::execute(SLIInterpreter *i) const
175175
// 1 0
176176
i->require_stack_load(2);
177177
i->EStack().pop();
178-
Token &val=i->pick(1);
179-
if(val==true )
178+
if(i->pick(1)==true)
180179
{
180+
i->EStack().push(i->top());
181181
if(i->step_mode())
182182
{
183183
std::cerr << "if:"
184184
<< " Executing true branch."
185185
<< std::endl;
186186
}
187-
i->EStack().push(i->top());
188187
}
189188
i->pop(2);
190189
}
@@ -215,8 +214,7 @@ void IfelseFunction::execute(SLIInterpreter *i) const
215214
i->require_stack_load(3);
216215
i->EStack().pop();
217216

218-
Token &val=i->pick(1);
219-
if(val==true )
217+
if(i->pick(1)==true )
220218
{
221219
if(i->step_mode())
222220
{
@@ -560,9 +558,7 @@ void LoadFunction::execute(SLIInterpreter *i) const
560558

561559
Name name(i->top().data_.name_val);
562560

563-
Token contents= i->lookup(name); // thows an exception if name is undefined
564-
i->pop();
565-
i->push(contents);
561+
i->top()=i->lookup(name);
566562
i->EStack().pop();
567563
}
568564

sli_dictionary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ void Dictionary::add_dict(const std::string& target,
101101
}
102102
}
103103
*/
104-
void Dictionary::remove(Name n)
104+
void Dictionary::remove(Name const & n)
105105
{
106106
TokenMap::iterator it = find(n);
107107
if ( it != end() )

sli_dictionary.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ namespace sli3
8080
bool access_flag_;
8181
};
8282

83+
//typedef std::map<Name, DictToken, std::less<Name> > TokenMap;
8384
typedef std::map<Name, DictToken, std::less<Name> > TokenMap;
8485

8586
inline bool operator==(const TokenMap & x, const TokenMap &y)
@@ -166,17 +167,17 @@ class Dictionary :private TokenMap
166167
* dictionary read-out is set on the Token in the dictionary,
167168
* not its copy.
168169
*/
169-
bool lookup(Name, DictToken &);
170-
DictToken & lookup(Name n); //throws UndefinedName
171-
bool known( Name ) const;
170+
bool lookup(Name const &, DictToken &);
171+
DictToken & lookup(Name const & n); //throws UndefinedName
172+
bool known( Name const & ) const;
172173

173-
DictToken & insert(Name , Token const &t);
174+
DictToken & insert(Name const & , Token const &t);
174175

175176
//! Remove entry from dictionary
176-
void remove(Name n);
177+
void remove(Name const & n);
177178

178-
const DictToken& operator[](Name) const;
179-
DictToken& operator[](Name );
179+
const DictToken& operator[](Name const &) const;
180+
DictToken& operator[](Name const & );
180181
const DictToken& operator[](const char*) const;
181182
DictToken& operator[](const char *);
182183

@@ -249,7 +250,7 @@ class Dictionary :private TokenMap
249250
/**
250251
*
251252
*/
252-
void initialize_property_array(Name propname);
253+
void initialize_property_array(Name const & propname);
253254

254255
/**
255256
* This function is called when a dictionary is pushed to the dictionary stack.
@@ -297,7 +298,7 @@ class Dictionary :private TokenMap
297298
};
298299

299300
inline
300-
bool Dictionary::lookup(Name n, DictToken &result)
301+
bool Dictionary::lookup(Name const & n, DictToken &result)
301302
{
302303
TokenMap::iterator where = find(n);
303304
if(where != end())
@@ -310,7 +311,7 @@ class Dictionary :private TokenMap
310311
}
311312

312313
inline
313-
DictToken& Dictionary::lookup(Name n)
314+
DictToken& Dictionary::lookup(Name const & n)
314315
{
315316
TokenMap::iterator where = find(n);
316317
if(where != end())
@@ -320,7 +321,7 @@ class Dictionary :private TokenMap
320321
}
321322

322323
inline
323-
bool Dictionary::known(Name n) const
324+
bool Dictionary::known(Name const & n) const
324325
{
325326
TokenMap::const_iterator where = find(n);
326327
if(where != end())
@@ -330,14 +331,14 @@ bool Dictionary::known(Name n) const
330331
}
331332

332333
inline
333-
DictToken& Dictionary::insert(Name n, Token const &t)
334+
DictToken& Dictionary::insert(Name const & n, Token const &t)
334335
{
335336
return TokenMap::operator[](n) = DictToken(t);
336337
}
337338

338339

339340
inline
340-
const DictToken& Dictionary::operator[](Name n) const
341+
const DictToken& Dictionary::operator[](Name const & n) const
341342
{
342343
TokenMap::const_iterator where = find(n);
343344
if(where != end())
@@ -348,7 +349,7 @@ const DictToken& Dictionary::operator[](Name n) const
348349

349350

350351
inline
351-
DictToken& Dictionary::operator[](Name n)
352+
DictToken& Dictionary::operator[](Name const& n)
352353
{
353354
return TokenMap::operator[](n);
354355
}

sli_dictstack.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ DictionaryStack::~DictionaryStack()
3838
(*i)->clear();
3939
}
4040

41-
void DictionaryStack::undef(Name n)
41+
void DictionaryStack::undef(Name const & n)
4242
{
4343

4444
size_t num_erased = 0;
@@ -55,7 +55,7 @@ void DictionaryStack::undef(Name n)
5555
#endif
5656
}
5757

58-
void DictionaryStack::basedef( Name n, const Token &t)
58+
void DictionaryStack::basedef( Name const & n, const Token &t)
5959
{
6060
//
6161
// insert (n,t) in bottom level dictionary

sli_dictstack.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ class DictionaryStack
7474
/**
7575
* Add a token to the cache.
7676
*/
77-
void cache_token( Name n, Token *result)
77+
void cache_token( Name const & n, Token *result)
7878
{
7979
Name::handle_t key=n.toIndex();
8080
if (key>=cache_.size())
8181
cache_.resize(Name::num_handles()+100,0);
8282
cache_[key]= result;
8383
}
8484

85-
void basecache_token(Name n, Token *result)
85+
void basecache_token(Name const & n, Token *result)
8686
{
8787
Name::handle_t key=n.toIndex();
8888
if (key>=basecache_.size())
@@ -94,14 +94,14 @@ class DictionaryStack
9494
* Clear a name from the cache.
9595
* This function should be called in each def variant.
9696
*/
97-
void clear_token_from_cache(Name n)
97+
void clear_token_from_cache(Name const & n)
9898
{
9999
Name::handle_t key=n.toIndex();
100100
if(key<cache_.size())
101101
cache_[key]=0;
102102
}
103103

104-
void clear_token_from_basecache(Name n)
104+
void clear_token_from_basecache(Name const & n)
105105
{
106106
Name::handle_t key=n.toIndex();
107107
if(key<basecache_.size())
@@ -127,7 +127,7 @@ class DictionaryStack
127127
cache_[i]=0;
128128
}
129129

130-
bool lookup(Name n, Token &result)
130+
bool lookup(Name const & n, Token &result)
131131
{
132132
Name::handle_t key=n.toIndex();
133133
if (key<cache_.size())
@@ -156,7 +156,7 @@ class DictionaryStack
156156
return false;
157157
}
158158

159-
Token& lookup(Name n)
159+
Token& lookup(Name const & n)
160160
{
161161
Name::handle_t key=n.toIndex();
162162
if (key<cache_.size())
@@ -181,7 +181,7 @@ class DictionaryStack
181181
throw UndefinedName(n.toString());
182182
}
183183

184-
bool known(Name n)
184+
bool known(Name const & n)
185185
{
186186
Token result;
187187
return lookup(n,result);
@@ -191,7 +191,7 @@ class DictionaryStack
191191
* If the Name is not found,
192192
* @a VoidToken is returned.
193193
*/
194-
Token& baselookup(Name n) // lookup in a specified
194+
Token& baselookup(Name const & n) // lookup in a specified
195195
{ // base dictionary
196196
Name::handle_t key=n.toIndex();
197197
if (key<basecache_.size())
@@ -219,24 +219,24 @@ class DictionaryStack
219219
/** Bind a Token to a Name in the top level dictionary.
220220
* The Token is copied.
221221
*/
222-
void def(Name , const Token &);
222+
void def(Name const & , const Token &);
223223

224224
/** Unbind a previously defined Name from its token. Seach in all dictionaries.
225225
*/
226-
void undef(Name );
226+
void undef(Name const & );
227227

228228
/** Bind a Token to a Name in the bottom level dictionary.
229229
* The Token is copied.
230230
*/
231-
void basedef(Name n, const Token &t);
231+
void basedef(Name const & n, const Token &t);
232232

233233
/**
234234
* This function must be called once to initialize the systemdict cache.
235235
*/
236236
void set_basedict();
237237

238238

239-
bool where(Name, Token&);
239+
bool where(Name const &, Token&);
240240

241241
void pop(void);
242242

@@ -263,7 +263,7 @@ class DictionaryStack
263263
};
264264

265265
inline
266-
void DictionaryStack::def(Name n, const Token &t)
266+
void DictionaryStack::def(Name const & n, const Token &t)
267267
{
268268
//
269269
// insert (n,t) in top level dictionary

sli_interpreter.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,11 @@ namespace sli3
198198
/**
199199
* Remove the top element from the operand stack.
200200
*/
201-
void pop(size_t n=1)
201+
void pop()
202+
{
203+
operand_stack_.pop();
204+
}
205+
void pop(size_t n)
202206
{
203207
operand_stack_.pop(n);
204208
}

sli_token.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ namespace sli3
3737

3838

3939
/**
40-
* Initialize from a Token.
40+
* Initialize from a Token. This function assumes that the object is uninitialized.
4141
*/
4242
Token & init(const Token &t);
4343

@@ -151,23 +151,21 @@ namespace sli3
151151
inline
152152
Token::~Token()
153153
{
154-
clear();
154+
remove_reference();
155155
}
156156

157157
inline
158158
void Token::clear()
159159
{
160-
if (type_)
161-
type_->remove_reference(*this);
160+
remove_reference();
162161
type_=0;
163-
data_=value();
162+
//data_=value();
164163
}
165164

166165
inline
167166
Token& Token::init(const Token&t)
168167
{
169168
t.add_reference();
170-
remove_reference();
171169
type_=t.type_;
172170
data_=t.data_;
173171
return *this;
@@ -176,6 +174,7 @@ namespace sli3
176174
inline
177175
Token& Token::move( Token&t)
178176
{
177+
clear();
179178
init(t);
180179
t.clear();
181180
return *this;
@@ -198,7 +197,8 @@ namespace sli3
198197
inline
199198
Token& Token::operator=(const Token &t)
200199
{
201-
return init(t);
200+
clear();
201+
return init(t);
202202
}
203203

204204
inline

0 commit comments

Comments
 (0)