moped-turbo 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+ # Overview
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Durran Jordan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ Moped Turbo[![Build Status](https://secure.travis-ci.org/mongoid/moped-turbo.png?branch=master&.png)](http://travis-ci.org/mongoid/moped-turbo)
2
+ ========
3
+
4
+ Moped Turbo is *experimental* C extensions for Moped, a Ruby driver for MongoDB
5
+
6
+ Roadmap
7
+ -------
8
+
9
+ We identify the parts of Moped that we can get significantly faster
10
+ in C, and add extensions for these areas. Moped's design should make
11
+ the C parts easy and small.
12
+
13
+ Currently the generation of `Moped::BSON::ObjectId` generation is handled
14
+ via the extension, which is roughly twice as fast as the raw Ruby version
15
+ for this task.
16
+
17
+ * Serialization/Deserialization of documents via `Document#serialize` and
18
+ `Document#deserialize`
19
+
20
+ Project Tracking
21
+ ----------------
22
+
23
+ * [Mongoid Google Group](http://groups.google.com/group/mongoid)
24
+ * [Moped Website and Documentation](http://mongoid.org/en/moped/)
25
+
26
+ Compatibility
27
+ -------------
28
+
29
+ Moped Turbo is tested against MRI 1.9.3, 2.0.0
30
+
31
+ Documentation
32
+ -------------
33
+
34
+ Please see the new Mongoid website for up-to-date documentation in
35
+ the Moped section: [mongoid.org](http://mongoid.org/en/moped/)
36
+
37
+ License
38
+ -------
39
+
40
+ Copyright (c) 2012 Durran Jordan
41
+
42
+ Permission is hereby granted, free of charge, to any person obtaining
43
+ a copy of this software and associated documentation files (the
44
+ "Software"), to deal in the Software without restriction, including
45
+ without limitation the rights to use, copy, modify, merge, publish,
46
+ distribute, sublicense, and/or sell copies of the Software, and to
47
+ permit persons to whom the Software is furnished to do so, subject to
48
+ the following conditions:
49
+
50
+ The above copyright notice and this permission notice shall be
51
+ included in all copies or substantial portions of the Software.
52
+
53
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
54
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
55
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
56
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
57
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
58
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
59
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
60
+
61
+ Credits
62
+ -------
63
+
64
+ Durran Jordan durran at gmail dot com
@@ -0,0 +1,3 @@
1
+ require "mkmf"
2
+ $CFLAGS << " -Wall -g"
3
+ create_makefile("moped/turbo")
@@ -0,0 +1,60 @@
1
+ #include <ruby.h>
2
+ #include <time.h>
3
+
4
+ /*
5
+ * Extension for generation of object ids.
6
+ *
7
+ * @return The generated object id.
8
+ *
9
+ * @since 0.0.0
10
+ */
11
+ static VALUE object_id_generator_next(VALUE self)
12
+ {
13
+ static int counter = 0;
14
+ char bytes[12];
15
+ int now = (int) time(0);
16
+ int incremented = counter++;
17
+
18
+ VALUE thread = rb_thread_current();
19
+ long thread_id = FIX2LONG(rb_obj_id(thread));
20
+
21
+ char *timestamp = (char*) &now;
22
+ char *machine = (char*) &thread_id;
23
+ char *count = (char*) &incremented;
24
+
25
+ /* 4 Bytes for the timestamp in big endian. */
26
+ bytes[0] = timestamp[3];
27
+ bytes[1] = timestamp[2];
28
+ bytes[2] = timestamp[1];
29
+ bytes[3] = timestamp[0];
30
+
31
+ /* 5 bytes machine id + thread id. */
32
+ bytes[4] = machine[0];
33
+ bytes[5] = machine[1];
34
+ bytes[6] = machine[2];
35
+ bytes[7] = machine[3];
36
+ bytes[8] = machine[4];
37
+
38
+ /* 4 bytes for the counter in big endian. */
39
+ bytes[9] = count[2];
40
+ bytes[10] = count[1];
41
+ bytes[11] = count[0];
42
+
43
+ return rb_str_new(bytes, 12);
44
+ }
45
+
46
+ /*
47
+ * Initialize the ObjectId by adding the appropriate methods to it.
48
+ *
49
+ * @param [ Module ] bson The BSON module.
50
+ *
51
+ * @since 0.0.0
52
+ */
53
+ void initialize_object_id(VALUE bson)
54
+ {
55
+ VALUE object_id = rb_const_get(bson, rb_intern("ObjectId"));
56
+ VALUE generator = rb_const_get(object_id, rb_intern("Generator"));
57
+
58
+ rb_remove_method(generator, "next");
59
+ rb_define_method(generator, "next", object_id_generator_next, 0);
60
+ }
@@ -0,0 +1,10 @@
1
+ #include <ruby.h>
2
+
3
+ /*
4
+ * Initialize the ObjectId by adding the appropriate methods to it.
5
+ *
6
+ * @param [ Module ] bson The BSON module.
7
+ *
8
+ * @since 0.0.0
9
+ */
10
+ void initialize_object_id(VALUE bson);
@@ -0,0 +1,14 @@
1
+ #include <ruby.h>
2
+ #include <object_id.h>
3
+
4
+ /*
5
+ * Initialize the moped turbo extensions.
6
+ *
7
+ * @since 0.0.0
8
+ */
9
+ void Init_turbo()
10
+ {
11
+ VALUE moped = rb_const_get(rb_cObject, rb_intern("Moped"));
12
+ VALUE bson = rb_const_get(moped, rb_intern("BSON"));
13
+ initialize_object_id(bson);
14
+ }
@@ -0,0 +1,3 @@
1
+ # encoding: utf-8
2
+ require "moped/turbo"
3
+ require "moped/turbo/version"
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ module Moped
3
+ module Turbo
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moped-turbo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Durran Jordan
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: moped
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ description: C extensions for Moped, a Ruby driver for MongoDB
31
+ email:
32
+ - durran@gmail.com
33
+ executables: []
34
+ extensions:
35
+ - ext/moped/turbo/extconf.rb
36
+ extra_rdoc_files: []
37
+ files:
38
+ - lib/moped/turbo/version.rb
39
+ - lib/moped-turbo.rb
40
+ - ext/moped/turbo/object_id.c
41
+ - ext/moped/turbo/turbo.c
42
+ - ext/moped/turbo/object_id.h
43
+ - ext/moped/turbo/extconf.rb
44
+ - CHANGELOG.md
45
+ - LICENSE
46
+ - README.md
47
+ homepage: http://mongoid.org/moped
48
+ licenses: []
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ segments:
60
+ - 0
61
+ hash: -1734233293886874738
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ! '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ segments:
69
+ - 0
70
+ hash: -1734233293886874738
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.24
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: C extensions for Moped, a Ruby driver for MongoDB
77
+ test_files: []