Optimize struct element initialization
[hiphop-php.git] / hphp / runtime / vm / repo-autoload-map-builder.cpp
blob3dfa58590cd8820580345f4330045b6de9ad7b89
1 /*
2 +----------------------------------------------------------------------+
3 | HipHop for PHP |
4 +----------------------------------------------------------------------+
5 | Copyright (c) 2010-present Facebook, Inc. (http://www.facebook.com) |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | http://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
17 #include "hphp/runtime/vm/repo-autoload-map-builder.h"
19 #include "hphp/runtime/vm/constant.h"
20 #include "hphp/runtime/vm/func-emitter.h"
21 #include "hphp/runtime/vm/preclass-emitter.h"
22 #include "hphp/runtime/vm/type-alias-emitter.h"
24 #include <boost/algorithm/string/predicate.hpp>
26 namespace HPHP {
28 //////////////////////////////////////////////////////////////////////
30 void RepoAutoloadMapBuilder::addUnit(const UnitEmitter& ue) {
31 auto unitSn = ue.m_sn;
32 assertx(unitSn != -1 && "unitSn is invalid");
33 for (size_t n = 0; n < ue.numPreClasses(); ++n) {
34 auto pce = ue.pce(n);
35 if (!boost::starts_with(pce->name()->slice(), "Closure$")) {
36 m_types.insert(std::make_pair(pce->name(), unitSn));
39 for (size_t n = 0; n < ue.numRecords(); ++n) {
40 auto re = ue.re(n);
41 m_types.insert(std::make_pair(re->name(), unitSn));
43 for (auto& fe : ue.fevec()) {
44 if (!fe->isMethod()
45 && !boost::ends_with(fe->name->slice(), "$memoize_impl")) {
46 m_funcs.insert(std::make_pair(fe->name, unitSn));
49 for (auto& te : ue.typeAliases()) {
50 m_typeAliases.insert(std::make_pair(te->name(), unitSn));
53 for (auto& c : ue.constants()) {
54 m_constants.insert(std::make_pair(c.name, unitSn));
58 void RepoAutoloadMapBuilder::serde(BlobEncoder& sd) const {
59 serdeMap(sd, m_types);
60 serdeMap(sd, m_funcs);
61 serdeMap(sd, m_typeAliases);
62 serdeMap(sd, m_constants);
65 std::unique_ptr<RepoAutoloadMap> RepoAutoloadMapBuilder::serde(BlobDecoder& sd) {
66 RepoAutoloadMap::CaseInsensitiveMap types = serdeMap<RepoAutoloadMap::CaseInsensitiveMap>(sd);
67 RepoAutoloadMap::CaseInsensitiveMap funcs = serdeMap<RepoAutoloadMap::CaseInsensitiveMap>(sd);
68 RepoAutoloadMap::CaseInsensitiveMap typeAliases = serdeMap<RepoAutoloadMap::CaseInsensitiveMap>(sd);
69 RepoAutoloadMap::CaseSensitiveMap constants = serdeMap<RepoAutoloadMap::CaseSensitiveMap>(sd);
70 return std::make_unique<RepoAutoloadMap>(types, funcs, constants, typeAliases);
73 //////////////////////////////////////////////////////////////////////