passenger 5.3.4 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +69 -0
- data/CONTRIBUTORS +1 -0
- data/README.md +2 -1
- data/Rakefile +0 -5
- data/build/agent.rb +6 -3
- data/build/cxx_tests.rb +28 -19
- data/build/integration_tests.rb +6 -2
- data/build/misc.rb +2 -1
- data/build/packaging.rb +2 -0
- data/build/support/cplusplus.rb +2 -2
- data/build/support/cxx_dependency_map.rb +2651 -2189
- data/dev/colorize-logs +272 -0
- data/dev/show-latest-crashlog-dir +27 -0
- data/resources/templates/standalone/http.erb +2 -0
- data/resources/templates/standalone/server.erb +1 -0
- data/src/agent/AgentMain.cpp +4 -0
- data/src/agent/Core/AdminPanelConnector.h +6 -6
- data/src/agent/Core/ApiServer.h +4 -4
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +2 -2
- data/src/agent/Core/ApplicationPool/Context.h +5 -1
- data/src/agent/Core/ApplicationPool/Group/InternalUtils.cpp +2 -2
- data/src/agent/Core/ApplicationPool/Group/LifetimeAndBasics.cpp +5 -0
- data/src/agent/Core/ApplicationPool/Group/Miscellaneous.cpp +2 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +3 -3
- data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/StateInspection.cpp +13 -20
- data/src/agent/Core/ApplicationPool/Group.h +4 -2
- data/src/agent/Core/ApplicationPool/Implementation.cpp +5 -5
- data/src/agent/Core/ApplicationPool/Options.h +42 -38
- data/src/agent/Core/ApplicationPool/Pool/GroupUtils.cpp +2 -1
- data/src/agent/Core/ApplicationPool/Pool.h +4 -4
- data/src/agent/Core/ApplicationPool/Process.h +13 -15
- data/src/agent/Core/ApplicationPool/Socket.h +5 -5
- data/src/agent/Core/ApplicationPool/TestSession.h +3 -3
- data/src/agent/Core/Config.h +50 -10
- data/src/agent/Core/ConfigChange.cpp +13 -1
- data/src/agent/Core/Controller/Config.h +41 -17
- data/src/agent/Core/Controller/ForwardResponse.cpp +4 -0
- data/src/agent/Core/Controller/InitRequest.cpp +14 -8
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +5 -0
- data/src/agent/Core/Controller/SendRequest.cpp +9 -9
- data/src/agent/Core/Controller/TurboCaching.h +2 -2
- data/src/agent/Core/Controller.h +7 -5
- data/src/agent/Core/CoreMain.cpp +204 -60
- data/src/agent/Core/OptionParser.h +20 -3
- data/src/agent/Core/ResponseCache.h +3 -3
- data/src/agent/Core/SecurityUpdateChecker.h +4 -2
- data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h +1 -1
- data/src/agent/Core/SpawningKit/Config.h +3 -2
- data/src/agent/Core/SpawningKit/Context.h +8 -2
- data/src/agent/Core/SpawningKit/DirectSpawner.h +4 -4
- data/src/agent/Core/SpawningKit/DummySpawner.h +3 -3
- data/src/agent/Core/SpawningKit/ErrorRenderer.h +1 -1
- data/src/agent/Core/SpawningKit/Exceptions.h +21 -14
- data/src/agent/Core/SpawningKit/Factory.h +1 -1
- data/src/agent/Core/SpawningKit/Handshake/BackgroundIOCapturer.h +1 -1
- data/src/agent/Core/SpawningKit/Handshake/Perform.h +14 -2
- data/src/agent/Core/SpawningKit/Handshake/Prepare.h +3 -3
- data/src/agent/Core/SpawningKit/Handshake/WorkDir.h +1 -1
- data/src/agent/Core/SpawningKit/Journey.h +4 -5
- data/src/agent/Core/SpawningKit/PipeWatcher.h +1 -1
- data/src/agent/Core/SpawningKit/README.md +34 -17
- data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h +1 -1
- data/src/agent/Core/SpawningKit/Result.h +20 -8
- data/src/agent/Core/SpawningKit/SmartSpawner.h +7 -7
- data/src/agent/Core/SpawningKit/Spawner.h +25 -8
- data/src/agent/Core/SpawningKit/UserSwitchingRules.h +17 -7
- data/src/agent/Core/TelemetryCollector.h +681 -0
- data/src/agent/ExecHelper/ExecHelperMain.cpp +1 -1
- data/src/agent/FileReadHelper/FileReadHelperMain.cpp +198 -0
- data/src/agent/README.md +1 -1
- data/src/agent/Shared/ApiAccountUtils.h +1 -1
- data/src/agent/Shared/ApiServerUtils.h +3 -3
- data/src/agent/Shared/ApplicationPoolApiKey.h +2 -2
- data/src/agent/Shared/Fundamentals/AbortHandler.cpp +324 -98
- data/src/agent/Shared/Fundamentals/AbortHandler.h +31 -4
- data/src/agent/Shared/Fundamentals/Initialization.cpp +4 -5
- data/src/agent/Shared/Fundamentals/Initialization.h +9 -1
- data/src/agent/SpawnEnvSetupper/SpawnEnvSetupperMain.cpp +1 -1
- data/src/agent/SystemMetrics/SystemMetricsMain.cpp +4 -3
- data/src/agent/TempDirToucher/TempDirToucherMain.cpp +3 -3
- data/src/agent/Watchdog/ApiServer.h +3 -3
- data/src/agent/Watchdog/Config.h +24 -5
- data/src/agent/Watchdog/CoreWatcher.cpp +2 -2
- data/src/agent/Watchdog/WatchdogMain.cpp +97 -28
- data/src/apache2_module/Config.cpp +14 -14
- data/src/apache2_module/Config.h +8 -16
- data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp +510 -481
- data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp.cxxcodebuilder +39 -17
- data/src/apache2_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.cpp +5 -0
- data/src/apache2_module/ConfigGeneral/AutoGeneratedSetterFuncs.cpp +69 -1
- data/src/apache2_module/ConfigGeneral/AutoGeneratedSetterFuncs.cpp.cxxcodebuilder +31 -1
- data/src/apache2_module/ConfigGeneral/Common.h +45 -0
- data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp +17 -1
- data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp.cxxcodebuilder +16 -1
- data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp +19 -5
- data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp.cxxcodebuilder +26 -9
- data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp +19 -1
- data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp.cxxcodebuilder +10 -1
- data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp +14 -1
- data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp.cxxcodebuilder +11 -1
- data/src/apache2_module/DirConfig/AutoGeneratedStruct.h +36 -1
- data/src/apache2_module/DirConfig/AutoGeneratedStruct.h.cxxcodebuilder +34 -1
- data/src/apache2_module/DirectoryMapper.h +36 -37
- data/src/apache2_module/Hooks.cpp +27 -8
- data/src/apache2_module/ServerConfig/AutoGeneratedManifestGeneration.cpp +20 -0
- data/src/apache2_module/ServerConfig/AutoGeneratedStruct.h +48 -1
- data/src/apache2_module/ServerConfig/AutoGeneratedStruct.h.cxxcodebuilder +36 -1
- data/src/cxx_supportlib/{Utils → Algorithms}/Hasher.cpp +2 -2
- data/src/cxx_supportlib/{Utils → Algorithms}/Hasher.h +4 -4
- data/src/cxx_supportlib/AppLocalConfigFileUtils.h +148 -0
- data/src/cxx_supportlib/AppTypeDetector/CBindings.cpp +147 -0
- data/src/cxx_supportlib/AppTypeDetector/CBindings.h +75 -0
- data/src/cxx_supportlib/{AppTypes.h → AppTypeDetector/Detector.h} +92 -131
- data/src/cxx_supportlib/ConfigKit/README.md +90 -2
- data/src/cxx_supportlib/ConfigKit/Schema.h +60 -15
- data/src/cxx_supportlib/ConfigKit/Store.h +129 -5
- data/src/cxx_supportlib/Constants.h +1 -1
- data/src/cxx_supportlib/{Utils → DataStructures}/HashMap.h +4 -4
- data/src/cxx_supportlib/DataStructures/HashedStaticString.h +5 -5
- data/src/cxx_supportlib/DataStructures/LString.h +3 -3
- data/src/cxx_supportlib/{Utils → DataStructures}/StringMap.h +36 -36
- data/src/cxx_supportlib/FileTools/FileManip.cpp +1 -1
- data/src/cxx_supportlib/FileTools/PathManip.cpp +2 -2
- data/src/cxx_supportlib/FileTools/PathSecurityCheck.cpp +1 -1
- data/src/cxx_supportlib/Hooks.h +2 -2
- data/src/cxx_supportlib/{Utils → IOTools}/BufferedIO.h +5 -5
- data/src/cxx_supportlib/{Utils → IOTools}/IOUtils.cpp +4 -3
- data/src/cxx_supportlib/{Utils → IOTools}/IOUtils.h +3 -3
- data/src/cxx_supportlib/{Utils → IOTools}/MessageIO.h +7 -7
- data/src/cxx_supportlib/{MessageReadersWriters.h → IOTools/MessageSerialization.h} +5 -5
- data/src/cxx_supportlib/InstanceDirectory.h +4 -4
- data/src/cxx_supportlib/Integrations/LibevJsonUtils.h +3 -3
- data/src/cxx_supportlib/{Utils → JsonTools}/JsonUtils.h +5 -5
- data/src/cxx_supportlib/LoggingKit/Context.h +2 -2
- data/src/cxx_supportlib/LoggingKit/Implementation.cpp +3 -3
- data/src/cxx_supportlib/MemoryKit/mbuf.cpp +2 -2
- data/src/cxx_supportlib/ProcessManagement/Ruby.cpp +3 -3
- data/src/cxx_supportlib/ProcessManagement/Ruby.h +7 -2
- data/src/cxx_supportlib/ProcessManagement/Spawn.cpp +19 -12
- data/src/cxx_supportlib/ProcessManagement/Spawn.h +21 -2
- data/src/cxx_supportlib/ProcessManagement/Utils.h +10 -0
- data/src/cxx_supportlib/RandomGenerator.h +2 -2
- data/src/cxx_supportlib/ResourceLocator.h +1 -1
- data/src/cxx_supportlib/{Crypto.cpp → SecurityKit/Crypto.cpp} +4 -4
- data/src/cxx_supportlib/{Crypto.h → SecurityKit/Crypto.h} +4 -4
- data/src/cxx_supportlib/{Utils → SecurityKit}/MemZeroGuard.h +0 -0
- data/src/cxx_supportlib/ServerKit/AcceptLoadBalancer.h +2 -2
- data/src/cxx_supportlib/ServerKit/Channel.h +1 -1
- data/src/cxx_supportlib/ServerKit/ClientRef.h +17 -7
- data/src/cxx_supportlib/ServerKit/Context.h +2 -2
- data/src/cxx_supportlib/ServerKit/FileBufferedChannel.h +1 -1
- data/src/cxx_supportlib/ServerKit/HttpHeaderParser.h +3 -3
- data/src/cxx_supportlib/ServerKit/HttpHeaderParserState.h +2 -2
- data/src/cxx_supportlib/ServerKit/HttpRequestRef.h +17 -7
- data/src/cxx_supportlib/ServerKit/HttpServer.h +16 -10
- data/src/cxx_supportlib/ServerKit/Server.h +3 -4
- data/src/cxx_supportlib/{Utils → StrIntTools}/DateParsing.h +5 -5
- data/src/cxx_supportlib/{Utils → StrIntTools}/StrIntUtils.cpp +3 -3
- data/src/cxx_supportlib/{Utils → StrIntTools}/StrIntUtils.h +0 -0
- data/src/cxx_supportlib/{Utils → StrIntTools}/StrIntUtilsNoStrictAliasing.cpp +12 -12
- data/src/cxx_supportlib/{Utils → StrIntTools}/StringScanning.h +5 -5
- data/src/cxx_supportlib/{Utils → StrIntTools}/Template.h +30 -5
- data/src/cxx_supportlib/SystemTools/ContainerHelpers.h +88 -0
- data/src/cxx_supportlib/{Utils → SystemTools}/ProcessMetricsCollector.h +15 -12
- data/src/cxx_supportlib/{Utils → SystemTools}/SystemMetricsCollector.h +3 -3
- data/src/cxx_supportlib/{Utils → SystemTools}/SystemTime.cpp +1 -1
- data/src/cxx_supportlib/{Utils → SystemTools}/SystemTime.h +0 -0
- data/src/cxx_supportlib/SystemTools/UserDatabase.h +1 -1
- data/src/cxx_supportlib/Utils/CachedFileStat.hpp +3 -3
- data/src/cxx_supportlib/Utils/Curl.h +2 -2
- data/src/cxx_supportlib/Utils/FileChangeChecker.h +2 -2
- data/src/cxx_supportlib/Utils/MessagePassing.h +1 -1
- data/src/cxx_supportlib/Utils/SpeedMeter.h +2 -2
- data/src/cxx_supportlib/Utils/Timer.h +2 -2
- data/src/cxx_supportlib/Utils/VariantMap.h +3 -3
- data/src/cxx_supportlib/Utils.cpp +2 -2
- data/src/cxx_supportlib/WatchdogLauncher.h +3 -3
- data/src/cxx_supportlib/WebSocketCommandReverseServer.h +1 -1
- data/src/cxx_supportlib/WrapperRegistry/CBindings.cpp +85 -0
- data/src/cxx_supportlib/{Utils/MemoryBarrier.h → WrapperRegistry/CBindings.h} +30 -27
- data/src/cxx_supportlib/WrapperRegistry/Entry.h +112 -0
- data/src/cxx_supportlib/WrapperRegistry/README.md +37 -0
- data/src/cxx_supportlib/WrapperRegistry/Registry.h +309 -0
- data/src/cxx_supportlib/vendor-modified/psg_sysqueue.h +3 -0
- data/src/helper-scripts/download_binaries/extconf.rb +6 -2
- data/src/nginx_module/ConfigGeneral/AutoGeneratedDefinitions.c +32 -0
- data/src/nginx_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.c +12 -0
- data/src/nginx_module/ConfigGeneral/AutoGeneratedSetterFuncs.c +36 -0
- data/src/nginx_module/Configuration.c +23 -3
- data/src/nginx_module/ContentHandler.c +331 -32
- data/src/nginx_module/ContentHandler.h +8 -3
- data/src/nginx_module/LocationConfig/AutoGeneratedCreateFunction.c +10 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedManifestGeneration.c +27 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c +3 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedStruct.h +7 -0
- data/src/nginx_module/MainConfig/AutoGeneratedCreateFunction.c +11 -0
- data/src/nginx_module/MainConfig/AutoGeneratedManifestGeneration.c +23 -0
- data/src/nginx_module/MainConfig/AutoGeneratedStruct.h +8 -0
- data/src/nginx_module/config +2 -1
- data/src/nginx_module/ngx_http_passenger_module.c +9 -3
- data/src/nginx_module/ngx_http_passenger_module.h +10 -3
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +19 -0
- data/src/ruby_supportlib/phusion_passenger/common_library.rb +19 -16
- data/src/ruby_supportlib/phusion_passenger/config/agent_compiler.rb +4 -4
- data/src/ruby_supportlib/phusion_passenger/config/download_agent_command.rb +6 -2
- data/src/ruby_supportlib/phusion_passenger/config/download_nginx_engine_command.rb +6 -2
- data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/message_channel.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/native_support.rb +7 -3
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +29 -0
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +20 -19
- data/src/ruby_supportlib/phusion_passenger/platform_info/apache.rb +22 -4
- data/src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb +33 -13
- data/src/ruby_supportlib/phusion_passenger/standalone/app_finder.rb +1 -0
- data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +22 -2
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +4 -1
- data/src/ruby_supportlib/phusion_passenger.rb +7 -5
- data/src/schema_printer/SchemaPrinterMain.cpp +2 -0
- metadata +40 -89
- data/.editorconfig +0 -134
- data/CODE_OF_CONDUCT.md +0 -52
- data/dev/boost-patches/0001-Patch-boost-thread-so-that-oxt-thread-can-use-it.patch +0 -48
- data/dev/boost-patches/0002-Make-boost-thread_interrupted-derive-from-oxt-tracab.patch +0 -33
- data/dev/boost-patches/0003-Disable-a-Clang-pragma-to-prevent-warnings-on-OS-X.patch +0 -25
- data/dev/ci/README.md +0 -134
- data/dev/ci/lib/functions.sh +0 -129
- data/dev/ci/lib/set-container-envvars.sh +0 -53
- data/dev/ci/lib/setup-container.sh +0 -46
- data/dev/ci/run-tests-natively +0 -24
- data/dev/ci/run-tests-with-docker +0 -42
- data/dev/ci/scripts/debug-console-wrapper.sh +0 -29
- data/dev/ci/scripts/docker-entrypoint-stage2.sh +0 -17
- data/dev/ci/scripts/docker-entrypoint.sh +0 -17
- data/dev/ci/scripts/inituidgid +0 -17
- data/dev/ci/scripts/run-tests-natively-stage2.sh +0 -17
- data/dev/ci/scripts/setup-host-natively.sh +0 -11
- data/dev/ci/setup-host +0 -56
- data/dev/ci/tests/apache2/run +0 -6
- data/dev/ci/tests/apache2/setup +0 -4
- data/dev/ci/tests/binaries/Jenkinsfile +0 -105
- data/dev/ci/tests/binaries/build-linux +0 -38
- data/dev/ci/tests/binaries/build-macos +0 -40
- data/dev/ci/tests/binaries/prepare-macos +0 -38
- data/dev/ci/tests/binaries/test-linux +0 -45
- data/dev/ci/tests/binaries/test-macos +0 -38
- data/dev/ci/tests/cxx/run +0 -9
- data/dev/ci/tests/cxx/setup +0 -4
- data/dev/ci/tests/debian/Jenkinsfile +0 -89
- data/dev/ci/tests/debian/run +0 -60
- data/dev/ci/tests/nginx/run +0 -5
- data/dev/ci/tests/nginx/setup +0 -4
- data/dev/ci/tests/nginx-dynamic/run +0 -20
- data/dev/ci/tests/nginx-dynamic/setup +0 -4
- data/dev/ci/tests/nodejs/run +0 -4
- data/dev/ci/tests/nodejs/setup +0 -4
- data/dev/ci/tests/rpm/Jenkinsfile +0 -68
- data/dev/ci/tests/rpm/run +0 -63
- data/dev/ci/tests/ruby/run +0 -4
- data/dev/ci/tests/ruby/setup +0 -4
- data/dev/ci/tests/source-packaging/run +0 -4
- data/dev/ci/tests/source-packaging/setup +0 -4
- data/dev/ci/tests/standalone/run +0 -4
- data/dev/ci/tests/standalone/setup +0 -4
- data/dev/configkit-schemas/index.json +0 -1748
- data/dev/configkit-schemas/update_schema_inline_comments.rb +0 -118
- data/dev/rack.test/config.ru +0 -5
- data/dev/rack.test/public/asset.txt +0 -1
- data/dev/vagrant/apache_default_site.conf +0 -35
- data/dev/vagrant/apache_passenger.conf +0 -5
- data/dev/vagrant/apache_passenger.load +0 -1
- data/dev/vagrant/apache_ports.conf +0 -24
- data/dev/vagrant/apache_rack_test.conf +0 -9
- data/dev/vagrant/bashrc +0 -23
- data/dev/vagrant/nginx.conf +0 -39
- data/dev/vagrant/nginx_rakefile +0 -33
- data/dev/vagrant/nginx_start +0 -32
- data/dev/vagrant/provision.sh +0 -117
- data/dev/vagrant/sudoers.conf +0 -5
- data/resources/templates/error_renderer/.editorconfig +0 -19
- data/src/cxx_supportlib/AppTypes.cpp +0 -109
- data/src/cxx_supportlib/vendor-modified/SmallVector.h +0 -653
@@ -1,653 +0,0 @@
|
|
1
|
-
//===- llvm/ADT/SmallVector.h - 'Normally small' vectors --------*- C++ -*-===//
|
2
|
-
//
|
3
|
-
// The LLVM Compiler Infrastructure
|
4
|
-
//
|
5
|
-
// This file is distributed under the University of Illinois Open Source
|
6
|
-
// License.
|
7
|
-
// ==============================================================================
|
8
|
-
// LLVM Release License
|
9
|
-
// ==============================================================================
|
10
|
-
// University of Illinois/NCSA
|
11
|
-
// Open Source License
|
12
|
-
//
|
13
|
-
// Copyright (c) 2003-2009 University of Illinois at Urbana-Champaign.
|
14
|
-
// All rights reserved.
|
15
|
-
//
|
16
|
-
// Developed by:
|
17
|
-
//
|
18
|
-
// LLVM Team
|
19
|
-
//
|
20
|
-
// University of Illinois at Urbana-Champaign
|
21
|
-
//
|
22
|
-
// http://llvm.org
|
23
|
-
//
|
24
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy of
|
25
|
-
// this software and associated documentation files (the "Software"), to deal with
|
26
|
-
// the Software without restriction, including without limitation the rights to
|
27
|
-
// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
28
|
-
// of the Software, and to permit persons to whom the Software is furnished to do
|
29
|
-
// so, subject to the following conditions:
|
30
|
-
//
|
31
|
-
// * Redistributions of source code must retain the above copyright notice,
|
32
|
-
// this list of conditions and the following disclaimers.
|
33
|
-
//
|
34
|
-
// * Redistributions in binary form must reproduce the above copyright notice,
|
35
|
-
// this list of conditions and the following disclaimers in the
|
36
|
-
// documentation and/or other materials provided with the distribution.
|
37
|
-
//
|
38
|
-
// * Neither the names of the LLVM Team, University of Illinois at
|
39
|
-
// Urbana-Champaign, nor the names of its contributors may be used to
|
40
|
-
// endorse or promote products derived from this Software without specific
|
41
|
-
// prior written permission.
|
42
|
-
//
|
43
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
44
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
45
|
-
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
46
|
-
// CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
47
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
48
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
|
49
|
-
// SOFTWARE.
|
50
|
-
//
|
51
|
-
//===----------------------------------------------------------------------===//
|
52
|
-
//
|
53
|
-
// This file defines the SmallVector class. Slightly modified for use in
|
54
|
-
// Phusion Passenger.
|
55
|
-
//
|
56
|
-
//===----------------------------------------------------------------------===//
|
57
|
-
|
58
|
-
#ifndef LLVM_ADT_SMALLVECTOR_H
|
59
|
-
#define LLVM_ADT_SMALLVECTOR_H
|
60
|
-
|
61
|
-
#include <iterator>
|
62
|
-
#include <boost/type_traits/is_class.hpp>
|
63
|
-
#include <algorithm>
|
64
|
-
#include <cassert>
|
65
|
-
#include <cstring>
|
66
|
-
#include <memory>
|
67
|
-
|
68
|
-
#ifdef _MSC_VER
|
69
|
-
namespace std {
|
70
|
-
#if _MSC_VER <= 1310
|
71
|
-
// Work around flawed VC++ implementation of std::uninitialized_copy. Define
|
72
|
-
// additional overloads so that elements with pointer types are recognized as
|
73
|
-
// scalars and not objects, causing bizarre type conversion errors.
|
74
|
-
template<class T1, class T2>
|
75
|
-
inline _Scalar_ptr_iterator_tag _Ptr_cat(T1 **, T2 **) {
|
76
|
-
_Scalar_ptr_iterator_tag _Cat;
|
77
|
-
return _Cat;
|
78
|
-
}
|
79
|
-
|
80
|
-
template<class T1, class T2>
|
81
|
-
inline _Scalar_ptr_iterator_tag _Ptr_cat(T1* const *, T2 **) {
|
82
|
-
_Scalar_ptr_iterator_tag _Cat;
|
83
|
-
return _Cat;
|
84
|
-
}
|
85
|
-
#else
|
86
|
-
// FIXME: It is not clear if the problem is fixed in VS 2005. What is clear
|
87
|
-
// is that the above hack won't work if it wasn't fixed.
|
88
|
-
#endif
|
89
|
-
}
|
90
|
-
#endif
|
91
|
-
|
92
|
-
namespace Passenger {
|
93
|
-
|
94
|
-
/// SmallVectorImpl - This class consists of common code factored out of the
|
95
|
-
/// SmallVector class to reduce code duplication based on the SmallVector 'N'
|
96
|
-
/// template parameter.
|
97
|
-
template <typename T>
|
98
|
-
class SmallVectorImpl {
|
99
|
-
protected:
|
100
|
-
T *Begin, *End, *Capacity;
|
101
|
-
|
102
|
-
// Allocate raw space for N elements of type T. If T has a ctor or dtor, we
|
103
|
-
// don't want it to be automatically run, so we need to represent the space as
|
104
|
-
// something else. An array of char would work great, but might not be
|
105
|
-
// aligned sufficiently. Instead, we either use GCC extensions, or some
|
106
|
-
// number of union instances for the space, which guarantee maximal alignment.
|
107
|
-
protected:
|
108
|
-
#ifdef __GNUC__
|
109
|
-
typedef char U;
|
110
|
-
U FirstEl __attribute__((aligned));
|
111
|
-
#else
|
112
|
-
union U {
|
113
|
-
double D;
|
114
|
-
long double LD;
|
115
|
-
long long L;
|
116
|
-
void *P;
|
117
|
-
} FirstEl;
|
118
|
-
#endif
|
119
|
-
// Space after 'FirstEl' is clobbered, do not add any instance vars after it.
|
120
|
-
public:
|
121
|
-
// Default ctor - Initialize to empty.
|
122
|
-
explicit SmallVectorImpl(unsigned N)
|
123
|
-
: Begin(reinterpret_cast<T*>(&FirstEl)),
|
124
|
-
End(reinterpret_cast<T*>(&FirstEl)),
|
125
|
-
Capacity(reinterpret_cast<T*>(&FirstEl)+N) {
|
126
|
-
}
|
127
|
-
|
128
|
-
~SmallVectorImpl() {
|
129
|
-
// Destroy the constructed elements in the vector.
|
130
|
-
destroy_range(Begin, End);
|
131
|
-
|
132
|
-
// If this wasn't grown from the inline copy, deallocate the old space.
|
133
|
-
if (!isSmall())
|
134
|
-
operator delete(Begin);
|
135
|
-
}
|
136
|
-
|
137
|
-
typedef size_t size_type;
|
138
|
-
typedef ptrdiff_t difference_type;
|
139
|
-
typedef T value_type;
|
140
|
-
typedef T* iterator;
|
141
|
-
typedef const T* const_iterator;
|
142
|
-
|
143
|
-
typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
|
144
|
-
typedef std::reverse_iterator<iterator> reverse_iterator;
|
145
|
-
|
146
|
-
typedef T& reference;
|
147
|
-
typedef const T& const_reference;
|
148
|
-
typedef T* pointer;
|
149
|
-
typedef const T* const_pointer;
|
150
|
-
|
151
|
-
bool empty() const { return Begin == End; }
|
152
|
-
size_type size() const { return End-Begin; }
|
153
|
-
size_type max_size() const { return size_type(-1) / sizeof(T); }
|
154
|
-
|
155
|
-
// forward iterator creation methods.
|
156
|
-
iterator begin() { return Begin; }
|
157
|
-
const_iterator begin() const { return Begin; }
|
158
|
-
iterator end() { return End; }
|
159
|
-
const_iterator end() const { return End; }
|
160
|
-
|
161
|
-
// reverse iterator creation methods.
|
162
|
-
reverse_iterator rbegin() { return reverse_iterator(end()); }
|
163
|
-
const_reverse_iterator rbegin() const{ return const_reverse_iterator(end()); }
|
164
|
-
reverse_iterator rend() { return reverse_iterator(begin()); }
|
165
|
-
const_reverse_iterator rend() const { return const_reverse_iterator(begin());}
|
166
|
-
|
167
|
-
|
168
|
-
/* These asserts could be "Begin + idx < End", but there are lots of places
|
169
|
-
in llvm where we use &v[v.size()] instead of v.end(). */
|
170
|
-
reference operator[](unsigned idx) {
|
171
|
-
assert (Begin + idx <= End);
|
172
|
-
return Begin[idx];
|
173
|
-
}
|
174
|
-
const_reference operator[](unsigned idx) const {
|
175
|
-
assert (Begin + idx <= End);
|
176
|
-
return Begin[idx];
|
177
|
-
}
|
178
|
-
|
179
|
-
reference front() {
|
180
|
-
return begin()[0];
|
181
|
-
}
|
182
|
-
const_reference front() const {
|
183
|
-
return begin()[0];
|
184
|
-
}
|
185
|
-
|
186
|
-
reference back() {
|
187
|
-
return end()[-1];
|
188
|
-
}
|
189
|
-
const_reference back() const {
|
190
|
-
return end()[-1];
|
191
|
-
}
|
192
|
-
|
193
|
-
void push_back(const_reference Elt) {
|
194
|
-
if (End < Capacity) {
|
195
|
-
Retry:
|
196
|
-
new (End) T(Elt);
|
197
|
-
++End;
|
198
|
-
return;
|
199
|
-
}
|
200
|
-
grow();
|
201
|
-
goto Retry;
|
202
|
-
}
|
203
|
-
|
204
|
-
void pop_back() {
|
205
|
-
--End;
|
206
|
-
End->~T();
|
207
|
-
}
|
208
|
-
|
209
|
-
T pop_back_val() {
|
210
|
-
T Result = back();
|
211
|
-
pop_back();
|
212
|
-
return Result;
|
213
|
-
}
|
214
|
-
|
215
|
-
void clear() {
|
216
|
-
destroy_range(Begin, End);
|
217
|
-
End = Begin;
|
218
|
-
}
|
219
|
-
|
220
|
-
void resize(unsigned N) {
|
221
|
-
if (N < size()) {
|
222
|
-
destroy_range(Begin+N, End);
|
223
|
-
End = Begin+N;
|
224
|
-
} else if (N > size()) {
|
225
|
-
if (unsigned(Capacity-Begin) < N)
|
226
|
-
grow(N);
|
227
|
-
construct_range(End, Begin+N, T());
|
228
|
-
End = Begin+N;
|
229
|
-
}
|
230
|
-
}
|
231
|
-
|
232
|
-
void resize(unsigned N, const T &NV) {
|
233
|
-
if (N < size()) {
|
234
|
-
destroy_range(Begin+N, End);
|
235
|
-
End = Begin+N;
|
236
|
-
} else if (N > size()) {
|
237
|
-
if (unsigned(Capacity-Begin) < N)
|
238
|
-
grow(N);
|
239
|
-
construct_range(End, Begin+N, NV);
|
240
|
-
End = Begin+N;
|
241
|
-
}
|
242
|
-
}
|
243
|
-
|
244
|
-
void reserve(unsigned N) {
|
245
|
-
if (unsigned(Capacity-Begin) < N)
|
246
|
-
grow(N);
|
247
|
-
}
|
248
|
-
|
249
|
-
void swap(SmallVectorImpl &RHS);
|
250
|
-
|
251
|
-
/// append - Add the specified range to the end of the SmallVector.
|
252
|
-
///
|
253
|
-
template<typename in_iter>
|
254
|
-
void append(in_iter in_start, in_iter in_end) {
|
255
|
-
size_type NumInputs = std::distance(in_start, in_end);
|
256
|
-
// Grow allocated space if needed.
|
257
|
-
if (NumInputs > size_type(Capacity-End))
|
258
|
-
grow(size()+NumInputs);
|
259
|
-
|
260
|
-
// Copy the new elements over.
|
261
|
-
std::uninitialized_copy(in_start, in_end, End);
|
262
|
-
End += NumInputs;
|
263
|
-
}
|
264
|
-
|
265
|
-
/// append - Add the specified range to the end of the SmallVector.
|
266
|
-
///
|
267
|
-
void append(size_type NumInputs, const T &Elt) {
|
268
|
-
// Grow allocated space if needed.
|
269
|
-
if (NumInputs > size_type(Capacity-End))
|
270
|
-
grow(size()+NumInputs);
|
271
|
-
|
272
|
-
// Copy the new elements over.
|
273
|
-
std::uninitialized_fill_n(End, NumInputs, Elt);
|
274
|
-
End += NumInputs;
|
275
|
-
}
|
276
|
-
|
277
|
-
void assign(unsigned NumElts, const T &Elt) {
|
278
|
-
clear();
|
279
|
-
if (unsigned(Capacity-Begin) < NumElts)
|
280
|
-
grow(NumElts);
|
281
|
-
End = Begin+NumElts;
|
282
|
-
construct_range(Begin, End, Elt);
|
283
|
-
}
|
284
|
-
|
285
|
-
iterator erase(iterator I) {
|
286
|
-
iterator N = I;
|
287
|
-
// Shift all elts down one.
|
288
|
-
std::copy(I+1, End, I);
|
289
|
-
// Drop the last elt.
|
290
|
-
pop_back();
|
291
|
-
return(N);
|
292
|
-
}
|
293
|
-
|
294
|
-
iterator erase(iterator S, iterator E) {
|
295
|
-
iterator N = S;
|
296
|
-
// Shift all elts down.
|
297
|
-
iterator I = std::copy(E, End, S);
|
298
|
-
// Drop the last elts.
|
299
|
-
destroy_range(I, End);
|
300
|
-
End = I;
|
301
|
-
return(N);
|
302
|
-
}
|
303
|
-
|
304
|
-
iterator insert(iterator I, const T &Elt) {
|
305
|
-
if (I == End) { // Important special case for empty vector.
|
306
|
-
push_back(Elt);
|
307
|
-
return end()-1;
|
308
|
-
}
|
309
|
-
|
310
|
-
if (End < Capacity) {
|
311
|
-
Retry:
|
312
|
-
new (End) T(back());
|
313
|
-
++End;
|
314
|
-
// Push everything else over.
|
315
|
-
std::copy_backward(I, End-1, End);
|
316
|
-
*I = Elt;
|
317
|
-
return I;
|
318
|
-
}
|
319
|
-
size_t EltNo = I-Begin;
|
320
|
-
grow();
|
321
|
-
I = Begin+EltNo;
|
322
|
-
goto Retry;
|
323
|
-
}
|
324
|
-
|
325
|
-
iterator insert(iterator I, size_type NumToInsert, const T &Elt) {
|
326
|
-
if (I == End) { // Important special case for empty vector.
|
327
|
-
append(NumToInsert, Elt);
|
328
|
-
return end()-1;
|
329
|
-
}
|
330
|
-
|
331
|
-
// Convert iterator to elt# to avoid invalidating iterator when we reserve()
|
332
|
-
size_t InsertElt = I-begin();
|
333
|
-
|
334
|
-
// Ensure there is enough space.
|
335
|
-
reserve(static_cast<unsigned>(size() + NumToInsert));
|
336
|
-
|
337
|
-
// Uninvalidate the iterator.
|
338
|
-
I = begin()+InsertElt;
|
339
|
-
|
340
|
-
// If there are more elements between the insertion point and the end of the
|
341
|
-
// range than there are being inserted, we can use a simple approach to
|
342
|
-
// insertion. Since we already reserved space, we know that this won't
|
343
|
-
// reallocate the vector.
|
344
|
-
if (size_t(end()-I) >= NumToInsert) {
|
345
|
-
T *OldEnd = End;
|
346
|
-
append(End-NumToInsert, End);
|
347
|
-
|
348
|
-
// Copy the existing elements that get replaced.
|
349
|
-
std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
|
350
|
-
|
351
|
-
std::fill_n(I, NumToInsert, Elt);
|
352
|
-
return I;
|
353
|
-
}
|
354
|
-
|
355
|
-
// Otherwise, we're inserting more elements than exist already, and we're
|
356
|
-
// not inserting at the end.
|
357
|
-
|
358
|
-
// Copy over the elements that we're about to overwrite.
|
359
|
-
T *OldEnd = End;
|
360
|
-
End += NumToInsert;
|
361
|
-
size_t NumOverwritten = OldEnd-I;
|
362
|
-
std::uninitialized_copy(I, OldEnd, End-NumOverwritten);
|
363
|
-
|
364
|
-
// Replace the overwritten part.
|
365
|
-
std::fill_n(I, NumOverwritten, Elt);
|
366
|
-
|
367
|
-
// Insert the non-overwritten middle part.
|
368
|
-
std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
|
369
|
-
return I;
|
370
|
-
}
|
371
|
-
|
372
|
-
template<typename ItTy>
|
373
|
-
iterator insert(iterator I, ItTy From, ItTy To) {
|
374
|
-
if (I == End) { // Important special case for empty vector.
|
375
|
-
append(From, To);
|
376
|
-
return end()-1;
|
377
|
-
}
|
378
|
-
|
379
|
-
size_t NumToInsert = std::distance(From, To);
|
380
|
-
// Convert iterator to elt# to avoid invalidating iterator when we reserve()
|
381
|
-
size_t InsertElt = I-begin();
|
382
|
-
|
383
|
-
// Ensure there is enough space.
|
384
|
-
reserve(static_cast<unsigned>(size() + NumToInsert));
|
385
|
-
|
386
|
-
// Uninvalidate the iterator.
|
387
|
-
I = begin()+InsertElt;
|
388
|
-
|
389
|
-
// If there are more elements between the insertion point and the end of the
|
390
|
-
// range than there are being inserted, we can use a simple approach to
|
391
|
-
// insertion. Since we already reserved space, we know that this won't
|
392
|
-
// reallocate the vector.
|
393
|
-
if (size_t(end()-I) >= NumToInsert) {
|
394
|
-
T *OldEnd = End;
|
395
|
-
append(End-NumToInsert, End);
|
396
|
-
|
397
|
-
// Copy the existing elements that get replaced.
|
398
|
-
std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
|
399
|
-
|
400
|
-
std::copy(From, To, I);
|
401
|
-
return I;
|
402
|
-
}
|
403
|
-
|
404
|
-
// Otherwise, we're inserting more elements than exist already, and we're
|
405
|
-
// not inserting at the end.
|
406
|
-
|
407
|
-
// Copy over the elements that we're about to overwrite.
|
408
|
-
T *OldEnd = End;
|
409
|
-
End += NumToInsert;
|
410
|
-
size_t NumOverwritten = OldEnd-I;
|
411
|
-
std::uninitialized_copy(I, OldEnd, End-NumOverwritten);
|
412
|
-
|
413
|
-
// Replace the overwritten part.
|
414
|
-
std::copy(From, From+NumOverwritten, I);
|
415
|
-
|
416
|
-
// Insert the non-overwritten middle part.
|
417
|
-
std::uninitialized_copy(From+NumOverwritten, To, OldEnd);
|
418
|
-
return I;
|
419
|
-
}
|
420
|
-
|
421
|
-
const SmallVectorImpl &operator=(const SmallVectorImpl &RHS);
|
422
|
-
|
423
|
-
bool operator==(const SmallVectorImpl &RHS) const {
|
424
|
-
if (size() != RHS.size()) return false;
|
425
|
-
for (T *This = Begin, *That = RHS.Begin, *E = Begin+size();
|
426
|
-
This != E; ++This, ++That)
|
427
|
-
if (*This != *That)
|
428
|
-
return false;
|
429
|
-
return true;
|
430
|
-
}
|
431
|
-
bool operator!=(const SmallVectorImpl &RHS) const { return !(*this == RHS); }
|
432
|
-
|
433
|
-
bool operator<(const SmallVectorImpl &RHS) const {
|
434
|
-
return std::lexicographical_compare(begin(), end(),
|
435
|
-
RHS.begin(), RHS.end());
|
436
|
-
}
|
437
|
-
|
438
|
-
private:
|
439
|
-
/// isSmall - Return true if this is a smallvector which has not had dynamic
|
440
|
-
/// memory allocated for it.
|
441
|
-
bool isSmall() const {
|
442
|
-
return static_cast<const void*>(Begin) ==
|
443
|
-
static_cast<const void*>(&FirstEl);
|
444
|
-
}
|
445
|
-
|
446
|
-
/// grow - double the size of the allocated memory, guaranteeing space for at
|
447
|
-
/// least one more element or MinSize if specified.
|
448
|
-
void grow(size_type MinSize = 0);
|
449
|
-
|
450
|
-
void construct_range(T *S, T *E, const T &Elt) {
|
451
|
-
for (; S != E; ++S)
|
452
|
-
new (S) T(Elt);
|
453
|
-
}
|
454
|
-
|
455
|
-
void destroy_range(T *S, T *E) {
|
456
|
-
while (S != E) {
|
457
|
-
--E;
|
458
|
-
E->~T();
|
459
|
-
}
|
460
|
-
}
|
461
|
-
};
|
462
|
-
|
463
|
-
// Define this out-of-line to dissuade the C++ compiler from inlining it.
|
464
|
-
template <typename T>
|
465
|
-
void SmallVectorImpl<T>::grow(size_t MinSize) {
|
466
|
-
size_t CurCapacity = Capacity-Begin;
|
467
|
-
size_t CurSize = size();
|
468
|
-
size_t NewCapacity = 2*CurCapacity;
|
469
|
-
if (NewCapacity < MinSize)
|
470
|
-
NewCapacity = MinSize;
|
471
|
-
T *NewElts = static_cast<T*>(operator new(NewCapacity*sizeof(T)));
|
472
|
-
|
473
|
-
// Copy the elements over.
|
474
|
-
if (boost::is_class<T>::value)
|
475
|
-
std::uninitialized_copy(Begin, End, NewElts);
|
476
|
-
else
|
477
|
-
// Use memcpy for PODs (std::uninitialized_copy optimizes to memmove).
|
478
|
-
memcpy(NewElts, Begin, CurSize * sizeof(T));
|
479
|
-
|
480
|
-
// Destroy the original elements.
|
481
|
-
destroy_range(Begin, End);
|
482
|
-
|
483
|
-
// If this wasn't grown from the inline copy, deallocate the old space.
|
484
|
-
if (!isSmall())
|
485
|
-
operator delete(Begin);
|
486
|
-
|
487
|
-
Begin = NewElts;
|
488
|
-
End = NewElts+CurSize;
|
489
|
-
Capacity = Begin+NewCapacity;
|
490
|
-
}
|
491
|
-
|
492
|
-
template <typename T>
|
493
|
-
void SmallVectorImpl<T>::swap(SmallVectorImpl<T> &RHS) {
|
494
|
-
if (this == &RHS) return;
|
495
|
-
|
496
|
-
// We can only avoid copying elements if neither vector is small.
|
497
|
-
if (!isSmall() && !RHS.isSmall()) {
|
498
|
-
std::swap(Begin, RHS.Begin);
|
499
|
-
std::swap(End, RHS.End);
|
500
|
-
std::swap(Capacity, RHS.Capacity);
|
501
|
-
return;
|
502
|
-
}
|
503
|
-
if (RHS.size() > size_type(Capacity-Begin))
|
504
|
-
grow(RHS.size());
|
505
|
-
if (size() > size_type(RHS.Capacity-RHS.begin()))
|
506
|
-
RHS.grow(size());
|
507
|
-
|
508
|
-
// Swap the shared elements.
|
509
|
-
size_t NumShared = size();
|
510
|
-
if (NumShared > RHS.size()) NumShared = RHS.size();
|
511
|
-
for (unsigned i = 0; i != static_cast<unsigned>(NumShared); ++i)
|
512
|
-
std::swap(Begin[i], RHS[i]);
|
513
|
-
|
514
|
-
// Copy over the extra elts.
|
515
|
-
if (size() > RHS.size()) {
|
516
|
-
size_t EltDiff = size() - RHS.size();
|
517
|
-
std::uninitialized_copy(Begin+NumShared, End, RHS.End);
|
518
|
-
RHS.End += EltDiff;
|
519
|
-
destroy_range(Begin+NumShared, End);
|
520
|
-
End = Begin+NumShared;
|
521
|
-
} else if (RHS.size() > size()) {
|
522
|
-
size_t EltDiff = RHS.size() - size();
|
523
|
-
std::uninitialized_copy(RHS.Begin+NumShared, RHS.End, End);
|
524
|
-
End += EltDiff;
|
525
|
-
destroy_range(RHS.Begin+NumShared, RHS.End);
|
526
|
-
RHS.End = RHS.Begin+NumShared;
|
527
|
-
}
|
528
|
-
}
|
529
|
-
|
530
|
-
template <typename T>
|
531
|
-
const SmallVectorImpl<T> &
|
532
|
-
SmallVectorImpl<T>::operator=(const SmallVectorImpl<T> &RHS) {
|
533
|
-
// Avoid self-assignment.
|
534
|
-
if (this == &RHS) return *this;
|
535
|
-
|
536
|
-
// If we already have sufficient space, assign the common elements, then
|
537
|
-
// destroy any excess.
|
538
|
-
unsigned RHSSize = unsigned(RHS.size());
|
539
|
-
unsigned CurSize = unsigned(size());
|
540
|
-
if (CurSize >= RHSSize) {
|
541
|
-
// Assign common elements.
|
542
|
-
iterator NewEnd;
|
543
|
-
if (RHSSize)
|
544
|
-
NewEnd = std::copy(RHS.Begin, RHS.Begin+RHSSize, Begin);
|
545
|
-
else
|
546
|
-
NewEnd = Begin;
|
547
|
-
|
548
|
-
// Destroy excess elements.
|
549
|
-
destroy_range(NewEnd, End);
|
550
|
-
|
551
|
-
// Trim.
|
552
|
-
End = NewEnd;
|
553
|
-
return *this;
|
554
|
-
}
|
555
|
-
|
556
|
-
// If we have to grow to have enough elements, destroy the current elements.
|
557
|
-
// This allows us to avoid copying them during the grow.
|
558
|
-
if (unsigned(Capacity-Begin) < RHSSize) {
|
559
|
-
// Destroy current elements.
|
560
|
-
destroy_range(Begin, End);
|
561
|
-
End = Begin;
|
562
|
-
CurSize = 0;
|
563
|
-
grow(RHSSize);
|
564
|
-
} else if (CurSize) {
|
565
|
-
// Otherwise, use assignment for the already-constructed elements.
|
566
|
-
std::copy(RHS.Begin, RHS.Begin+CurSize, Begin);
|
567
|
-
}
|
568
|
-
|
569
|
-
// Copy construct the new elements in place.
|
570
|
-
std::uninitialized_copy(RHS.Begin+CurSize, RHS.End, Begin+CurSize);
|
571
|
-
|
572
|
-
// Set end.
|
573
|
-
End = Begin+RHSSize;
|
574
|
-
return *this;
|
575
|
-
}
|
576
|
-
|
577
|
-
/// SmallVector - This is a 'vector' (really, a variable-sized array), optimized
|
578
|
-
/// for the case when the array is small. It contains some number of elements
|
579
|
-
/// in-place, which allows it to avoid heap allocation when the actual number of
|
580
|
-
/// elements is below that threshold. This allows normal "small" cases to be
|
581
|
-
/// fast without losing generality for large inputs.
|
582
|
-
///
|
583
|
-
/// Note that this does not attempt to be exception safe.
|
584
|
-
///
|
585
|
-
template <typename T, unsigned N>
|
586
|
-
class SmallVector : public SmallVectorImpl<T> {
|
587
|
-
/// InlineElts - These are 'N-1' elements that are stored inline in the body
|
588
|
-
/// of the vector. The extra '1' element is stored in SmallVectorImpl.
|
589
|
-
typedef typename SmallVectorImpl<T>::U U;
|
590
|
-
enum {
|
591
|
-
// MinUs - The number of U's require to cover N T's.
|
592
|
-
MinUs = (static_cast<unsigned int>(sizeof(T))*N +
|
593
|
-
static_cast<unsigned int>(sizeof(U)) - 1) /
|
594
|
-
static_cast<unsigned int>(sizeof(U)),
|
595
|
-
|
596
|
-
// NumInlineEltsElts - The number of elements actually in this array. There
|
597
|
-
// is already one in the parent class, and we have to round up to avoid
|
598
|
-
// having a zero-element array.
|
599
|
-
NumInlineEltsElts = MinUs > 1 ? (MinUs - 1) : 1,
|
600
|
-
|
601
|
-
// NumTsAvailable - The number of T's we actually have space for, which may
|
602
|
-
// be more than N due to rounding.
|
603
|
-
NumTsAvailable = (NumInlineEltsElts+1)*static_cast<unsigned int>(sizeof(U))/
|
604
|
-
static_cast<unsigned int>(sizeof(T))
|
605
|
-
};
|
606
|
-
U InlineElts[NumInlineEltsElts];
|
607
|
-
public:
|
608
|
-
SmallVector() : SmallVectorImpl<T>(NumTsAvailable) {
|
609
|
-
}
|
610
|
-
|
611
|
-
explicit SmallVector(unsigned Size, const T &Value = T())
|
612
|
-
: SmallVectorImpl<T>(NumTsAvailable) {
|
613
|
-
this->reserve(Size);
|
614
|
-
while (Size--)
|
615
|
-
this->push_back(Value);
|
616
|
-
}
|
617
|
-
|
618
|
-
template<typename ItTy>
|
619
|
-
SmallVector(ItTy S, ItTy E) : SmallVectorImpl<T>(NumTsAvailable) {
|
620
|
-
this->append(S, E);
|
621
|
-
}
|
622
|
-
|
623
|
-
SmallVector(const SmallVector &RHS) : SmallVectorImpl<T>(NumTsAvailable) {
|
624
|
-
if (!RHS.empty())
|
625
|
-
SmallVectorImpl<T>::operator=(RHS);
|
626
|
-
}
|
627
|
-
|
628
|
-
const SmallVector &operator=(const SmallVector &RHS) {
|
629
|
-
SmallVectorImpl<T>::operator=(RHS);
|
630
|
-
return *this;
|
631
|
-
}
|
632
|
-
|
633
|
-
};
|
634
|
-
|
635
|
-
} // End Passenger namespace
|
636
|
-
|
637
|
-
namespace std {
|
638
|
-
/// Implement std::swap in terms of SmallVector swap.
|
639
|
-
template<typename T>
|
640
|
-
inline void
|
641
|
-
swap(Passenger::SmallVectorImpl<T> &LHS, Passenger::SmallVectorImpl<T> &RHS) {
|
642
|
-
LHS.swap(RHS);
|
643
|
-
}
|
644
|
-
|
645
|
-
/// Implement std::swap in terms of SmallVector swap.
|
646
|
-
template<typename T, unsigned N>
|
647
|
-
inline void
|
648
|
-
swap(Passenger::SmallVector<T, N> &LHS, Passenger::SmallVector<T, N> &RHS) {
|
649
|
-
LHS.swap(RHS);
|
650
|
-
}
|
651
|
-
}
|
652
|
-
|
653
|
-
#endif
|