Merge lp:~matthias-brantner/zorba/bug-fixing into lp:zorba

Proposed by Matthias Brantner
Status: Merged
Approved by: Markos Zaharioudakis
Approved revision: no longer in the source branch.
Merged at revision: 10520
Proposed branch: lp:~matthias-brantner/zorba/bug-fixing
Merge into: lp:zorba
Diff against target: 444 lines (+177/-46)
6 files modified
src/compiler/translator/translator.cpp (+1/-0)
src/context/dynamic_context.cpp (+72/-25)
src/context/dynamic_context.h (+15/-8)
src/zorbaserialization/zorba_class_versions.cpp (+5/-5)
src/zorbautils/hashmap_zstring.h (+8/-8)
src/zorbautils/hashmap_zstring_nonserializable.h (+76/-0)
To merge this branch: bzr merge lp:~matthias-brantner/zorba/bug-fixing
Reviewer Review Type Date Requested Status
Markos Zaharioudakis Approve
Matthias Brantner Approve
Review via email: mp+79743@code.launchpad.net

Commit message

Optimization. Lazily create the external function parameter hashmap. This saves a lot of time every time the dynamic context is copied, i.e. on every function invocation.

Description of the change

Optimization. Lazily create the external function parameter hashmap. This saves a lot of time every time the dynamic context is copied, i.e. on every function invocation.

To post a comment you must log in.
Revision history for this message
Matthias Brantner (matthias-brantner) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-fixing-2011-10-18T22-36-08.666Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1. Got: 1 Approve, 1 Pending.

Revision history for this message
Markos Zaharioudakis (markos-za) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-fixing-2011-10-18T23-00-00.712Z is finished. The final status was:

All tests succeeded!

10520. By Matthias Brantner

Optimization. Lazily create the external function parameter hashmap. This saves a lot of time every time the dynamic context is copied, i.e. on every function invocation. Approved: Markos Zaharioudakis, Matthias Brantner

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/compiler/translator/translator.cpp'
2--- src/compiler/translator/translator.cpp 2011-10-03 09:18:49 +0000
3+++ src/compiler/translator/translator.cpp 2011-10-18 22:22:26 +0000
4@@ -101,6 +101,7 @@
5 #include "util/tracer.h"
6 #include "util/utf8_util.h"
7 #include "util/xml_util.h"
8+#include "util/hashmap.h"
9
10
11 #define NODE_SORT_OPT
12
13=== modified file 'src/context/dynamic_context.cpp'
14--- src/context/dynamic_context.cpp 2011-10-03 09:18:49 +0000
15+++ src/context/dynamic_context.cpp 2011-10-18 22:22:26 +0000
16@@ -120,6 +120,7 @@
17 dynamic_context::dynamic_context(dynamic_context* parent)
18 :
19 theParent(NULL),
20+ keymap(NULL),
21 theAvailableIndices(NULL),
22 theDocLoadingUserTime(0.0),
23 theDocLoadingTime(0)
24@@ -144,13 +145,20 @@
25 ********************************************************************************/
26 dynamic_context::~dynamic_context()
27 {
28- for (uint32_t i = 0; i < keymap.size(); ++i)
29+ if (keymap)
30 {
31- dctx_value_t lValue = keymap.getentryVal(i);
32- if (lValue.type == dctx_value_t::ext_func_param_typed && lValue.func_param)
33+ for (ValueMap::iterator lIter = keymap->begin();
34+ lIter != keymap->end();
35+ ++lIter)
36 {
37- static_cast<ExternalFunctionParameter*>(lValue.func_param)->destroy();
38+ dctx_value_t lValue = lIter.getValue();
39+ if (lValue.type == dctx_value_t::ext_func_param_typed &&
40+ lValue.func_param)
41+ {
42+ static_cast<ExternalFunctionParameter*>(lValue.func_param)->destroy();
43+ }
44 }
45+ delete keymap;
46 }
47
48 if (theAvailableIndices)
49@@ -572,7 +580,20 @@
50 val.type = dynamic_context::dctx_value_t::ext_func_param;
51 val.func_param = aValue;
52
53- return keymap.put ( aName, val);
54+ if (!keymap)
55+ {
56+ keymap = new ValueMap(8, false);
57+ }
58+
59+ if (!keymap->insert(aName, val))
60+ {
61+ keymap->update(aName, val);
62+ return false;
63+ }
64+ else
65+ {
66+ return true;
67+ }
68 }
69
70
71@@ -583,11 +604,24 @@
72 const std::string& aName,
73 void*& aValue) const
74 {
75+ if (!keymap)
76+ {
77+ if (theParent)
78+ {
79+ return theParent->getExternalFunctionParam(aName, aValue);
80+ }
81+ else
82+ {
83+ return false;
84+ }
85+ }
86+
87 dctx_value_t val;
88 val.type = dynamic_context::dctx_value_t::no_val;
89 val.func_param = 0;
90
91- if ( !keymap.get(aName, val) )
92+ ValueMap::iterator lIter = keymap->find(aName);
93+ if ( lIter == keymap->end() )
94 {
95 if (theParent)
96 return theParent->getExternalFunctionParam(aName, aValue);
97@@ -595,6 +629,8 @@
98 return false;
99 }
100
101+ val = lIter.getValue();
102+
103 if (val.type == dynamic_context::dctx_value_t::ext_func_param)
104 {
105 aValue = val.func_param;
106@@ -615,6 +651,11 @@
107 const std::string& aName,
108 ExternalFunctionParameter* aValue)
109 {
110+ if (!keymap)
111+ {
112+ keymap = new ValueMap(8, false);
113+ }
114+
115 dctx_value_t val;
116 val.type = dynamic_context::dctx_value_t::ext_func_param_typed;
117 val.func_param = aValue;
118@@ -624,8 +665,15 @@
119 {
120 // destroy the object if it's already contained in the map
121 lValue->destroy();
122- }
123- return keymap.put ( aName, val);
124+ keymap->erase(aName);
125+ keymap->insert(aName, val);
126+ return false;
127+ }
128+ else
129+ {
130+ keymap->insert(aName, val);
131+ return true;
132+ }
133 }
134
135
136@@ -635,11 +683,24 @@
137 ExternalFunctionParameter*
138 dynamic_context::getExternalFunctionParameter(const std::string& aName) const
139 {
140+ if (!keymap)
141+ {
142+ if (theParent)
143+ {
144+ return theParent->getExternalFunctionParameter(aName);
145+ }
146+ else
147+ {
148+ return 0;
149+ }
150+ }
151+
152 dctx_value_t val;
153 val.type = dynamic_context::dctx_value_t::no_val;
154 val.func_param = 0;
155
156- if ( !keymap.get(aName, val) )
157+ ValueMap::iterator lIter = keymap->find(aName);
158+ if (lIter == keymap->end())
159 {
160 if (theParent)
161 return theParent->getExternalFunctionParameter(aName);
162@@ -647,28 +708,14 @@
163 return 0;
164 }
165
166+ val = lIter.getValue();
167+
168 ExternalFunctionParameter* lRes =
169 static_cast<ExternalFunctionParameter*>(val.func_param);
170
171 return lRes;
172 }
173
174-/*
175-std::vector<zstring>* dynamic_context::get_all_keymap_keys() const
176-{
177- std::auto_ptr<std::vector<zstring> > keys;
178- if (theParent != NULL)
179- keys.reset(theParent->get_all_keymap_keys());
180- else
181- keys.reset(new std::vector<zstring>);
182-
183- for (unsigned int i=0; i<keymap.size(); i++)
184- keys->push_back(keymap.getentryKey(i));
185-
186- return keys.release();
187-}
188-*/
189-
190
191 } // namespace zorba
192 /* vim:set et sw=2 ts=2: */
193
194=== modified file 'src/context/dynamic_context.h'
195--- src/context/dynamic_context.h 2011-10-03 09:18:49 +0000
196+++ src/context/dynamic_context.h 2011-10-18 22:22:26 +0000
197@@ -17,7 +17,8 @@
198 #ifndef ZORBA_DYNAMIC_CONTEXT_H
199 #define ZORBA_DYNAMIC_CONTEXT_H
200
201-#include "util/hashmap.h"
202+#include <zorba/external_function_parameter.h>
203+#include "zorbautils/hashmap_zstring_nonserializable.h"
204
205 #include "common/shared_types.h"
206
207@@ -94,8 +95,7 @@
208 ~VarValue();
209 };
210
211- // QQQ zstring?
212- typedef hashmap<std::string, dctx_value_t> ValueMap;
213+ typedef HashMapZString<dctx_value_t> ValueMap;
214
215 typedef ItemPointerHashMap<store::Index_t> IndexMap;
216
217@@ -109,7 +109,7 @@
218
219 std::vector<VarValue> theVarValues;
220
221- ValueMap keymap;
222+ ValueMap * keymap;
223
224 IndexMap * theAvailableIndices;
225
226@@ -202,12 +202,19 @@
227 ExternalFunctionParameter* getExternalFunctionParameter(
228 const std::string& aName) const;
229
230- //std::vector<zstring>* get_all_keymap_keys() const;
231-
232 protected:
233 bool lookup_once(const std::string& key, dctx_value_t& val) const
234 {
235- return keymap.get(key, val);
236+ if (keymap)
237+ {
238+ ValueMap::iterator lIter = keymap->find(key);
239+ if (lIter != keymap->end())
240+ {
241+ val = lIter.getValue();
242+ return true;
243+ }
244+ }
245+ return false;
246 }
247
248 bool context_value(const std::string& key, dctx_value_t& val) const
249@@ -223,7 +230,7 @@
250 {
251 if (lookup_once (key, val))
252 {
253- if (map != NULL) *map = &keymap;
254+ if (map != NULL) *map = keymap;
255 return true;
256 }
257 return theParent == NULL ? false : theParent->context_value(key, val, map);
258
259=== modified file 'src/zorbaserialization/zorba_class_versions.cpp'
260--- src/zorbaserialization/zorba_class_versions.cpp 2011-06-14 17:26:33 +0000
261+++ src/zorbaserialization/zorba_class_versions.cpp 2011-10-18 22:22:26 +0000
262@@ -130,22 +130,22 @@
263
264
265 // HashMapZString
266-SERIALIZABLE_CLASS_VERSIONS(HashMapZStringCmp)
267-END_SERIALIZABLE_CLASS_VERSIONS(HashMapZStringCmp)
268+SERIALIZABLE_CLASS_VERSIONS(serializable_HashMapZStringCmp)
269+END_SERIALIZABLE_CLASS_VERSIONS(serializable_HashMapZStringCmp)
270
271 SERIALIZABLE_TEMPLATE_VERSIONS(serializable_HashMapZString)
272 END_SERIALIZABLE_TEMPLATE_VERSIONS(serializable_HashMapZString)
273
274 SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(serializable_HashEntry, serializable_HashEntry<zstring, static_context::ctx_module_t>, 11)
275
276-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(serializable_HashMap, serializable_HashMap<zstring, static_context::ctx_module_t, HashMapZStringCmp>, 11)
277+SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(serializable_HashMap, serializable_HashMap<zstring, static_context::ctx_module_t, serializable_HashMapZStringCmp>, 11)
278
279 SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(serializable_HashMapZString, serializable_HashMapZString<static_context::ctx_module_t>, 1)
280
281
282 SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS2(serializable_HashEntry, serializable_HashEntry<zstring, zstring>, 12)
283
284-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(serializable_HashMap, serializable_HashMap<zstring, zstring, HashMapZStringCmp>,12)
285+SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(serializable_HashMap, serializable_HashMap<zstring, zstring, serializable_HashMapZStringCmp>,12)
286
287 SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(serializable_HashMapZString, serializable_HashMapZString<zstring>, 2)
288
289@@ -155,7 +155,7 @@
290
291 SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS(serializable_HashMapZString, serializable_HashMapZString<xqtref_t>, 3)
292
293-SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(serializable_HashMap, serializable_HashMap<zstring, xqtref_t, HashMapZStringCmp>,13)
294+SERIALIZABLE_TEMPLATE_INSTANCE_VERSIONS3(serializable_HashMap, serializable_HashMap<zstring, xqtref_t, serializable_HashMapZStringCmp>,13)
295
296
297
298
299=== modified file 'src/zorbautils/hashmap_zstring.h'
300--- src/zorbautils/hashmap_zstring.h 2011-06-14 17:26:33 +0000
301+++ src/zorbautils/hashmap_zstring.h 2011-10-18 22:22:26 +0000
302@@ -33,7 +33,7 @@
303 Class to privide the equality and hash functions for the HashMapZString
304 class defined below.
305 *******************************************************************************/
306-class HashMapZStringCmp : public ::zorba::serialization::SerializeBaseClass
307+class serializable_HashMapZStringCmp : public ::zorba::serialization::SerializeBaseClass
308 {
309 public:
310 static uint32_t hash(const zstring& str)
311@@ -47,9 +47,9 @@
312 }
313
314 public:
315- SERIALIZABLE_CLASS(HashMapZStringCmp);
316+ SERIALIZABLE_CLASS(serializable_HashMapZStringCmp);
317
318- HashMapZStringCmp(::zorba::serialization::Archiver& ar)
319+ serializable_HashMapZStringCmp(::zorba::serialization::Archiver& ar)
320 {
321 }
322
323@@ -57,7 +57,7 @@
324 {
325 }
326
327- HashMapZStringCmp()
328+ serializable_HashMapZStringCmp()
329 {
330 }
331 };
332@@ -70,27 +70,27 @@
333 template<class V>
334 class serializable_HashMapZString : public serializable_HashMap<zstring,
335 V,
336- HashMapZStringCmp>
337+ serializable_HashMapZStringCmp>
338 {
339 public:
340 SERIALIZABLE_TEMPLATE_CLASS(serializable_HashMapZString)
341
342 serializable_HashMapZString(::zorba::serialization::Archiver& ar)
343 :
344- serializable_HashMap<zstring, V, HashMapZStringCmp>(ar)
345+ serializable_HashMap<zstring, V, serializable_HashMapZStringCmp>(ar)
346 {
347 }
348
349 void serialize(::zorba::serialization::Archiver& ar)
350 {
351 serialize_baseclass(ar,
352- (serializable_HashMap<zstring, V, HashMapZStringCmp>*)this);
353+ (serializable_HashMap<zstring, V, serializable_HashMapZStringCmp>*)this);
354 }
355
356 public:
357 serializable_HashMapZString(ulong size, bool sync)
358 :
359- serializable_HashMap<zstring, V, HashMapZStringCmp>(size, sync)
360+ serializable_HashMap<zstring, V, serializable_HashMapZStringCmp>(size, sync)
361 {
362 }
363
364
365=== added file 'src/zorbautils/hashmap_zstring_nonserializable.h'
366--- src/zorbautils/hashmap_zstring_nonserializable.h 1970-01-01 00:00:00 +0000
367+++ src/zorbautils/hashmap_zstring_nonserializable.h 2011-10-18 22:22:26 +0000
368@@ -0,0 +1,76 @@
369+/*
370+ * Copyright 2006-2008 The FLWOR Foundation.
371+ *
372+ * Licensed under the Apache License, Version 2.0 (the "License");
373+ * you may not use this file except in compliance with the License.
374+ * You may obtain a copy of the License at
375+ *
376+ * http://www.apache.org/licenses/LICENSE-2.0
377+ *
378+ * Unless required by applicable law or agreed to in writing, software
379+ * distributed under the License is distributed on an "AS IS" BASIS,
380+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
381+ * See the License for the specific language governing permissions and
382+ * limitations under the License.
383+ */
384+#pragma once
385+#ifndef ZORBA_HASHMAP_ZSTRING_NONSERIALIZABLE
386+#define ZORBA_HASHMAP_ZSTRING_NONSERIALIZABLE
387+
388+#undef ZORBA_UTILS_HASHMAP_WITH_SERIALIZATION
389+#include "zorbautils/hashmap.h"
390+
391+#include "zorbatypes/zstring.h"
392+
393+#include "util/utf8_util.h"
394+
395+
396+namespace zorba
397+{
398+
399+/***************************************************************************//**
400+ Class to privide the equality and hash functions for the HashMapZString
401+ class defined below.
402+*******************************************************************************/
403+class HashMapZStringCmp
404+{
405+public:
406+ static uint32_t hash(const zstring& str)
407+ {
408+ return utf8::hash(str);
409+ }
410+
411+ static bool equal(const zstring& s1, const zstring& s2)
412+ {
413+ return s1 == s2;
414+ }
415+};
416+
417+
418+/*******************************************************************************
419+ A nonserializable hash-based map container mapping zstrings to values of
420+ type V. Equality is based on the zstring == operator.
421+*******************************************************************************/
422+template<class V>
423+class HashMapZString : public HashMap<zstring, V, HashMapZStringCmp>
424+{
425+public:
426+ HashMapZString()
427+ :
428+ HashMap<zstring, V, HashMapZStringCmp>()
429+ {
430+ }
431+
432+public:
433+ HashMapZString(ulong size, bool sync)
434+ :
435+ HashMap<zstring, V, HashMapZStringCmp>(size, sync)
436+ {
437+ }
438+
439+ virtual ~HashMapZString() { }
440+};
441+
442+}
443+
444+#endif

Subscribers

People subscribed via source and target branches