void benchmark_VectorMap(const Vector<T>& key, const Vector<T>& fkey, int count) { StopTime(); cout << count << " items\n"; { int i; VectorMap<T, int> map; StopTime(); for(i = 0; i < count; i++) map.Add(key[i], i); cout << "Adding done in " << StopTime() << " s\n"; for(int j = 0; j < 2; j++) { for(i = 0; i < count; i++) if(map.Get(fkey[i]) != i) { cout << "ERROR !\n"; abort(); } cout << "Search done in " << StopTime() << " s\n"; } for(i = 0; i < count; i++) map.UnlinkKey(key[i]); cout << "Unlinking done in " << StopTime() << " s\n"; for(i = 0; i < count; i++) map.Put(key[i], i); cout << "Putting done in " << StopTime() << " s\n"; } }
Time GetFileTimeCached(const String& p) { LTIMING("GetFileTimeCached"); int q = sPathFileTime.Find(p); if(q >= 0) return sPathFileTime[q]; Time m = FileGetTime(p); sPathFileTime.Put(p, m); return m; }
void LoadPPConfig() { for(int i = 0; i < sAllMacros.GetCount(); i++) if(sAllMacros[i].segment_id == 0 && !sAllMacros.IsUnlinked(i)) sAllMacros.Unlink(i); s_namespace_macro.Clear(); s_namespace_end_macro.Clear(); StringStream ss(sDefs); int linei = 0; while(!ss.IsEof()) { String l = ss.GetLine(); try { CParser p(l); if(p.Char('#')) { if(p.Id("define")) { CppMacro def; String id = def.Define(p.GetPtr()); if(id.GetCount()) { PPMacro m; m.segment_id = 0; m.line = linei; m.macro = def; sAllMacros.Put(id, m); if(findarg(TrimBoth(def.body), "}", "};") >= 0) s_namespace_end_macro.Add(id); try { CParser p(def.body); if(p.Id("namespace") && p.IsId()) { String n = p.ReadId(); if(p.Char('{') && p.IsEof()) s_namespace_macro.Add(id, n); } } catch(CParser::Error) {} } } } } catch(CParser::Error) {} linei++; } }
void PPFile::Parse(Stream& in) { LTIMING("PPFile::Parse"); for(int i = 0; i < ppmacro.GetCount(); i++) sAllMacros.Unlink(ppmacro[i]); ppmacro.Clear(); item.Clear(); includes.Clear(); bool was_using = false; bool was_namespace = false; int level = 0; bool incomment = false; Vector<int> namespace_block; bool next_segment = true; Index<int> local_segments; keywords.Clear(); int linei = 0; Md5Stream md5; while(!in.IsEof()) { String l = in.GetLine(); while(*l.Last() == '\\' && !in.IsEof()) { l.Trim(l.GetLength() - 1); l.Cat(in.GetLine()); } RemoveComments(l, incomment); try { CParser p(l); if(p.Char('#')) { if(p.Id("define")) { if(next_segment) { PPItem& m = item.Add(); m.type = PP_DEFINES; m.segment_id = ++sPPserial; next_segment = false; local_segments.Add(sPPserial); } CppMacro def; String id = def.Define(p.GetPtr()); if(id.GetCount()) { PPMacro m; m.segment_id = sPPserial; m.line = linei; m.macro = def; ppmacro.Add(sAllMacros.Put(id, m)); md5.Put("#", 1); md5.Put(id); md5.Put(0); md5.Put(m.macro.md5, 16); } } else if(p.Id("undef")) { if(p.IsId()) { String id = p.ReadId(); md5.Put("#", 1); md5.Put(id); md5.Put(1); int segmenti = -1; PPMacro *um = FindPPMacro(id, local_segments, segmenti); if(um && segmenti) { // heuristic: only local undefs are allowed PPItem& m = item.Add(); m.type = PP_DEFINES; m.segment_id = ++sPPserial; um->undef_segment_id = m.segment_id; next_segment = true; local_segments.Add(sPPserial); if(id.GetCount()) { PPMacro m; m.segment_id = sPPserial; m.line = linei; m.macro.SetUndef(); ppmacro.Add(sAllMacros.Put(id, m)); } } } } else if(p.Id("include")) { PPItem& m = item.Add(); next_segment = true; m.type = PP_INCLUDE; m.text = TrimBoth(p.GetPtr()); if(IsNull(m.text)) item.Drop(); else includes.FindAdd(m.text); md5.Put('@'); md5.Put(m.text); } } else { while(!p.IsEof()) { if(was_namespace) { int type = was_using ? PP_USING : PP_NAMESPACE; String id; while(p.Char2(':', ':')) id = "::"; if(p.IsId()) { id << p.ReadId(); while(p.Char2(':', ':') && p.IsId()) id << "::" << p.ReadId(); if(!was_using) namespace_block.Add(level); if(!was_using || level == 0) { PPItem& m = item.Add(); next_segment = true; m.type = type; m.text = id; } md5.Put('$'); md5.Put(type); md5.Put(id); } was_namespace = was_using = false; } else if(p.Id("using")) was_using = true; else if(p.Id("namespace")) was_namespace = true; else { was_using = was_namespace = false; if(p.IsId()) { static const VectorMap<String, String>& namespace_macro = GetNamespaceMacros(); static const Index<String>& namespace_end_macro = GetNamespaceEndMacros(); String id = p.ReadId(); int q = namespace_macro.Find(id); if(q > 0) { PPItem& m = item.Add(); next_segment = true; m.type = PP_NAMESPACE; m.text = namespace_macro[q]; namespace_block.Add(level); level++; md5.Put('%'); md5.Put(id); } else { q = namespace_end_macro.Find(id); if(q >= 0) { level--; CheckEndNamespace(namespace_block, level, md5); } } keywords.Add(id); } else if(p.Char('}')) { if(level > 0) { level--; CheckEndNamespace(namespace_block, level, md5); } } else if(p.Char('{')) level++; else p.SkipTerm(); } } } } catch(...) {} linei++; } md5sum = md5.FinishString(); Sort(keywords); Vector<int> remove; int i = 0; while(i < keywords.GetCount()) { // Remove identical items int ii = i; i++; while(i < keywords.GetCount() && keywords[ii] == keywords[i]) remove.Add(i++); } keywords.Remove(remove); }