This commit is contained in:
邹晓航
2014-09-22 19:25:07 +08:00
parent 1e4df1ff55
commit 962b0d5f44
5 changed files with 34 additions and 23 deletions

View File

@@ -77,6 +77,7 @@
</ItemDefinitionGroup> </ItemDefinitionGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp" /> <ClCompile Include="main.cpp" />
<ClCompile Include="Profiler\Profiler.cpp" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="Algorithm.h" /> <ClInclude Include="Algorithm.h" />
@@ -84,6 +85,7 @@
<ClInclude Include="Allocator.h" /> <ClInclude Include="Allocator.h" />
<ClInclude Include="Construct.h" /> <ClInclude Include="Construct.h" />
<ClInclude Include="Iterator.h" /> <ClInclude Include="Iterator.h" />
<ClInclude Include="Profiler\Profiler.h" />
<ClInclude Include="TypeTraits.h" /> <ClInclude Include="TypeTraits.h" />
<ClInclude Include="UninitializedFunctions.h" /> <ClInclude Include="UninitializedFunctions.h" />
<ClInclude Include="Vector.h" /> <ClInclude Include="Vector.h" />

View File

@@ -13,11 +13,17 @@
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier> <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions> <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter> </Filter>
<Filter Include="头文件\Profiler">
<UniqueIdentifier>{092c2875-2b56-404b-977e-a9b4aa67c134}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="main.cpp"> <ClCompile Include="main.cpp">
<Filter>源文件</Filter> <Filter>源文件</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Profiler\Profiler.cpp">
<Filter>头文件\Profiler</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="TypeTraits.h"> <ClInclude Include="TypeTraits.h">
@@ -44,5 +50,8 @@
<ClInclude Include="Algorithm.h"> <ClInclude Include="Algorithm.h">
<Filter>头文件</Filter> <Filter>头文件</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Profiler\Profiler.h">
<Filter>头文件\Profiler</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -69,22 +69,22 @@ namespace TinySTL{
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first, ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first,
Size n, const T& x, _true_type); Size n, const T& x, _true_type);
template<class ForwardIterator, class Size, class T> template<class ForwardIterator, class Size, class T>
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first, ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first,
Size n, const T& x, _false_type); Size n, const T& x, _false_type);
template<class ForwardIterator, class Size, class T> template<class ForwardIterator, class Size, class T>
inline ForwardIterator uninitialized_fill_n(ForwardIterator first, inline ForwardIterator uninitialized_fill_n(ForwardIterator first,
Size n, const T& x){ Size n, const T& x){
typedef typename _type_traits<T>::is_POD_type isPODType; typedef typename _type_traits<T>::is_POD_type isPODType;
return _uninitialized_n_fill_aux(first, n, x, isPODType()); return _uninitialized_fill_n_aux(first, n, x, isPODType());
} }
template<class ForwardIterator, class Size, class T> template<class ForwardIterator, class Size, class T>
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first, ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first,
Size n, const T& x, _true_type){ Size n, const T& x, _true_type){
return fill_n(first, n, x); return fill_n(first, n, x);
} }
template<class ForwardIterator, class Size, class T> template<class ForwardIterator, class Size, class T>
ForwardIterator _uninitialized_n_fill_aux(ForwardIterator first, ForwardIterator _uninitialized_fill_n_aux(ForwardIterator first,
Size n, const T& x, _false_type){ Size n, const T& x, _false_type){
int i = 0; int i = 0;
for (; i != n; ++i){ for (; i != n; ++i){

View File

@@ -162,7 +162,7 @@ namespace TinySTL{
template<class InputIterator> template<class InputIterator>
void allocateAndCopy(InputIterator first, InputIterator last){ void allocateAndCopy(InputIterator first, InputIterator last){
start_ = dataAllocator::allocate(last - first); start_ = dataAllocator::allocate(last - first);
finish_ = uninitialized_copy(first, last, start_); finish_ = TinySTL::uninitialized_copy(first, last, start_);
endOfStorage_ = finish_; endOfStorage_ = finish_;
} }
@@ -171,13 +171,13 @@ namespace TinySTL{
allocateAndCopy(first, last); allocateAndCopy(first, last);
} }
template<class Integer> template<class Integer>
void vector_aux(Integer n, Integer value, std::true_type){ void vector_aux(Integer n, const value_type& value, std::true_type){
allocateAndFillN(n, value); allocateAndFillN(n, value);
} }
template<class InputIterator> template<class InputIterator>
void insert_aux(iterator position, InputIterator first, InputIterator last, std::false_type); void insert_aux(iterator position, InputIterator first, InputIterator last, std::false_type);
template<class Integer> template<class Integer>
void insert_aux(iterator position, Integer n, Integer value, std::true_type); void insert_aux(iterator position, Integer n, const value_type& value, std::true_type);
template<class InputIterator> template<class InputIterator>
void reallocateAndCopy(iterator position, InputIterator first, InputIterator last); void reallocateAndCopy(iterator position, InputIterator first, InputIterator last);
void reallocateAndFillN(iterator position, const size_type& n, const value_type& val); void reallocateAndFillN(iterator position, const size_type& n, const value_type& val);
@@ -247,9 +247,9 @@ namespace TinySTL{
T *newStart = dataAllocator::allocate(newCapacity); T *newStart = dataAllocator::allocate(newCapacity);
T *newEndOfStorage = newStart + newCapacity; T *newEndOfStorage = newStart + newCapacity;
T *newFinish = uninitialized_copy(begin(), position, newStart); T *newFinish = TinySTL::uninitialized_copy(begin(), position, newStart);
newFinish = uninitialized_copy(first, last, newFinish); newFinish = TinySTL::uninitialized_copy(first, last, newFinish);
newFinish = uninitialized_copy(position, end(), newFinish); newFinish = TinySTL::uninitialized_copy(position, end(), newFinish);
destroyAndDeallocateAll(); destroyAndDeallocateAll();
start_ = newStart; start_ = newStart;
@@ -262,9 +262,9 @@ namespace TinySTL{
T *newStart = dataAllocator::allocate(newCapacity); T *newStart = dataAllocator::allocate(newCapacity);
T *newEndOfStorage = newStart + newCapacity; T *newEndOfStorage = newStart + newCapacity;
T *newFinish = uninitialized_copy(begin(), position, newStart); T *newFinish = TinySTL::uninitialized_copy(begin(), position, newStart);
newFinish = uninitialized_fill_n(newFinish, n, val); newFinish = TinySTL::uninitialized_fill_n(newFinish, n, val);
newFinish = uninitialized_copy(position, end(), newFinish); newFinish = TinySTL::uninitialized_copy(position, end(), newFinish);
destroyAndDeallocateAll(); destroyAndDeallocateAll();
start_ = newStart; start_ = newStart;
@@ -285,7 +285,7 @@ namespace TinySTL{
for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back
*(tempPtr + locationNeed) = *tempPtr; *(tempPtr + locationNeed) = *tempPtr;
} }
uninitialized_copy(first, last, position); TinySTL::uninitialized_copy(first, last, position);
finish_ += locationNeed; finish_ += locationNeed;
}else{ }else{
reallocateAndCopy(position, first, last); reallocateAndCopy(position, first, last);
@@ -293,7 +293,7 @@ namespace TinySTL{
} }
template<class T, class Alloc> template<class T, class Alloc>
template<class Integer> template<class Integer>
void vector<T, Alloc>::insert_aux(iterator position, Integer n, Integer value, std::true_type){ void vector<T, Alloc>::insert_aux(iterator position, Integer n, const value_type& value, std::true_type){
assert(n != 0); assert(n != 0);
difference_type locationLeft = endOfStorage_ - finish_; // the size of left storage difference_type locationLeft = endOfStorage_ - finish_; // the size of left storage
difference_type locationNeed = n; difference_type locationNeed = n;
@@ -303,7 +303,7 @@ namespace TinySTL{
for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back for (; tempPtr - position >= 0; --tempPtr){//move the [position, finish_) back
*(tempPtr + locationNeed) = *tempPtr; *(tempPtr + locationNeed) = *tempPtr;
} }
uninitialized_fill_n(position, n, value); TinySTL::uninitialized_fill_n(position, n, value);
finish_ += locationNeed; finish_ += locationNeed;
} }
else{ else{
@@ -317,7 +317,7 @@ namespace TinySTL{
} }
template<class T, class Alloc> template<class T, class Alloc>
void vector<T, Alloc>::insert(iterator position, const size_type& n, const value_type& val){ void vector<T, Alloc>::insert(iterator position, const size_type& n, const value_type& val){
insert_aux(position, n, val, typename std::is_integral<value_type>::type()); insert_aux(position, n, val, typename std::is_integral<size_type>::type());
} }
template<class T, class Alloc> template<class T, class Alloc>
typename vector<T, Alloc>::iterator vector<T, Alloc>::insert(iterator position, const value_type& val){ typename vector<T, Alloc>::iterator vector<T, Alloc>::insert(iterator position, const value_type& val){

View File

@@ -15,16 +15,16 @@ using namespace TinySTL::Profiler;
int main(){ int main(){
int array[100000] = { 1 }; //std::vector<std::string> vec;
std::vector<int> vec; //TinySTL::vector<std::string> vec;
//TinySTL::vector<int> vec; TinySTL::vector<int> vec;
ProfilerInstance::start(); ProfilerInstance::start();
int i = 0; int i = 0;
for (; i != 10000000; ++i){ for (; i != 10000; ++i){
//vec.insert(vec.end(), array, array + 1); //vec.push_back(std::string("zouxiaohang"));
vec.push_back(i); vec.push_back(i);
} }
//vec.insert(vec.end(), array, array + 100000); //for (auto i : vec){ cout << i << endl; }
ProfilerInstance::finish(); ProfilerInstance::finish();
ProfilerInstance::dumpDuringTime(); ProfilerInstance::dumpDuringTime();
system("pause"); system("pause");