Browse files

change back header-only bson

  • Loading branch information...
1 parent 4cb2fac commit c8ae18d4b4118443bd084be51d75669113eb79dc Alberto Lerner committed Aug 3, 2010
Showing with 50 additions and 43 deletions.
  1. +0 −34 bson/bson.cpp
  2. +2 −3 bson/bsondemo/bsondemo.vcxproj
  3. +2 −3 bson/bsondemo/bsondemo.vcxproj.filters
  4. +33 −0 bson/inline_decls.h
  5. +13 −1 bson/util/builder.h
  6. +0 −2 db/jsobj.cpp
View
34 bson/bson.cpp
@@ -1,34 +0,0 @@
-/* bson.cpp
-*/
-
-#include "util/builder.h"
-
-namespace mongo {
-
- /* there is an inline-only subset of the bson library; however, it is best if grow_reallocate function is not inlined to
- improve performance. Thus grow_reallocate is here. The idea is that this file is a very MINIMAL set of code
- for use when using the C++ BSON library and that it does not pull in a lot of other code prerequisites.
-
- bsondemo.cpp will compile and link with itself and this file only (no libs) -- that's the idea.
-
- jsobj.cpp currently #include's this file, so don't include both bson.cpp and jsobj.cpp in your project
- at the same time -- just use jsobj.cpp if you need all that...
-
- This is interim and will evolve, but gets bsondemo.cpp compiling again sans libraries.
- */
-
- /* BufBuilder --------------------------------------------------------*/
-
- void BufBuilder::grow_reallocate() {
- int a = size * 2;
- if ( a == 0 )
- a = 512;
- if ( l > a )
- a = l + 16 * 1024;
- if( a > 64 * 1024 * 1024 )
- msgasserted(10000, "BufBuilder grow() > 64MB");
- data = (char *) realloc(data, a);
- size= a;
- }
-
-}
View
5 bson/bsondemo/bsondemo.vcxproj
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@@ -170,7 +170,6 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
- <ClCompile Include="..\bson.cpp" />
<ClCompile Include="bsondemo.cpp" />
</ItemGroup>
<ItemGroup>
@@ -191,4 +190,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
View
5 bson/bsondemo/bsondemo.vcxproj.filters
@@ -1,8 +1,7 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="bsondemo.cpp" />
- <ClCompile Include="..\bson.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\ordering.h">
@@ -50,4 +49,4 @@
<UniqueIdentifier>{ea599740-3c6f-40dd-a121-e825d82ae4aa}</UniqueIdentifier>
</Filter>
</ItemGroup>
-</Project>
+</Project>
View
33 bson/inline_decls.h
@@ -0,0 +1,33 @@
+// inline.h
+
+/**
+* Copyright (C) 2010 10gen Inc.
+*
+* This program is free software: you can redistribute it and/or modify
+* it under the terms of the GNU Affero General Public License, version 3,
+* as published by the Free Software Foundation.
+*
+* This program is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU Affero General Public License for more details.
+*
+* You should have received a copy of the GNU Affero General Public License
+* along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#pragma once
+
+#if defined(__GNUC__)
+
+#define NOINLINE_DECL __attribute__((noinline))
+
+#elif defined(_MSC_VER)
+
+#define NOINLINE_DECL __declspec(noinline)
+
+#else
+
+#define NOINLINE_DECL
+
+#endif
View
14 bson/util/builder.h
@@ -21,6 +21,8 @@
#include <string.h>
#include <stdio.h>
#include <boost/shared_ptr.hpp>
+
+#include "../inline_decls.h"
#include "../stringdata.h"
namespace mongo {
@@ -130,7 +132,17 @@ namespace mongo {
private:
/* "slow" portion of 'grow()' */
- void grow_reallocate();
+ void NOINLINE_DECL grow_reallocate(){
+ int a = size * 2;
+ if ( a == 0 )
+ a = 512;
+ if ( l > a )
+ a = l + 16 * 1024;
+ if( a > 64 * 1024 * 1024 )
+ msgasserted(10000, "BufBuilder grow() > 64MB");
+ data = (char *) realloc(data, a);
+ size= a;
+ }
char *data;
int l;
View
2 db/jsobj.cpp
@@ -40,8 +40,6 @@ BOOST_STATIC_ASSERT( sizeof(double) == 8 );
BOOST_STATIC_ASSERT( sizeof(mongo::Date_t) == 8 );
BOOST_STATIC_ASSERT( sizeof(mongo::OID) == 12 );
-#include "../bson/bson.cpp"
-
namespace mongo {
BSONElement nullElement;

0 comments on commit c8ae18d

Please sign in to comment.