Skip to content

Instantly share code, notes, and snippets.

View methodmissing's full-sized avatar

Lourens Naudé methodmissing

View GitHub Profile
#
# = ostruct.rb: OpenStruct implementation
#
# Author:: Yukihiro Matsumoto
# Documentation:: Gavin Sinclair
#
# OpenStruct allows the creation of data objects with arbitrary attributes.
# See OpenStruct for an example.
#
/* Tests for AIO in librt.
Copyright (C) 1998,2000,02 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
=begin
macbook-pros-computer:~ lourens$ ruby gc.rb
Collected 1112060
Collected 1112130
Collected 1112200
Collected 1112270
Collected 1112340
=end
include ObjectSpace
static VALUE
internal_read_func(void *ptr)
{
struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
return read(iis->fd, iis->buf, iis->capa);
}
static VALUE
internal_write_func(void *ptr)
{
#include "ruby.h"
#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#ifdef _POSIX_ASYNCHRONOUS_IO
#include <aio.h>
static VALUE
internal_read_func(void *ptr)
{
struct io_internal_struct *iis = (struct io_internal_struct*)ptr;
return read(iis->fd, iis->buf, iis->capa);
}
static VALUE
internal_write_func(void *ptr)
{
* The constants supported by Ruby for use with IO::fcntl are:
*
* - F_DUPFD - duplicate a close-on-exec file handle to a non-close-on-exec
* file handle.
*
* - F_GETFD - read the close-on-exec flag of a file handle.
*
* - F_SETFD - set the close-on-exec flag of a file handle.
*
* - FD_CLOEXEC - the value of the close-on-exec flag.
typedef struct OpenFile {
FILE *f; /* stdio ptr for read/write */
FILE *f2; /* additional ptr for rw pipes */
int mode; /* mode flags */
int pid; /* child's pid (for pipes) */
int lineno; /* number of lines read */
char *path; /* pathname for file */
void (*finalize) _((struct OpenFile*,int)); /* finalize proc */
} OpenFile;
macbook-pros-computer:~ lourens$ ruby hash_query.rb
Rehearsal ----------------------------------------------------------------------
fast_reverse_merge!: 0.020000 0.000000 0.020000 ( 0.021689)
fast_reverse_merge! (indifferent): 0.280000 0.000000 0.280000 ( 0.290316)
reverse_merge! 0.030000 0.000000 0.030000 ( 0.041295)
reverse_merge! (indifferent) 0.330000 0.000000 0.330000 ( 0.339491)
------------------------------------------------------------- total: 0.660000sec
user system total real
fast_reverse_merge!: 0.020000 0.000000 0.020000 ( 0.021406)
require 'rubygems'
require 'active_support'
require "benchmark"
class Hash
def fast_reverse_merge!(other_hash)
if respond_to?(:convert_key, true)
replace(reverse_merge(other_hash))
else