Staging
v0.5.1
https://github.com/python/cpython
Revision dfb495937437c62793489250df9d9dd33ac0f5a5 authored by Mark Dickinson on 28 September 2009, 16:59:12 UTC, committed by Mark Dickinson on 28 September 2009, 16:59:12 UTC
........
  r75110 | mark.dickinson | 2009-09-28 17:52:40 +0100 (Mon, 28 Sep 2009) | 9 lines

  Style/consistency/nano-optimization nit:  replace occurrences of
    (high_bits << PyLong_SHIFT) + low_bits with
    (high_bits << PyLong_SHIFT) | low_bits
  in Objects/longobject.c.  Motivation:
   - shouldn't unnecessarily mix bit ops with arithmetic ops (style)
   - this pattern should be spelt the same way thoughout (consistency)
   - it's very very very slightly faster: no need to worry about
     carries to the high digit (nano-optimization).
........
1 parent e1698eb
Raw File
Tip revision: dfb495937437c62793489250df9d9dd33ac0f5a5 authored by Mark Dickinson on 28 September 2009, 16:59:12 UTC
Blocked revisions 75110 via svnmerge
Tip revision: dfb4959
asdl.c
#include "Python.h"
#include "asdl.h"

asdl_seq *
asdl_seq_new(int size, PyArena *arena)
{
	asdl_seq *seq = NULL;
	size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);

	/* check size is sane */
	if (size < 0 || size == INT_MIN || 
		(size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
		PyErr_NoMemory();
		return NULL;
	}

	/* check if size can be added safely */
	if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
		PyErr_NoMemory();
		return NULL;
	}

	n += sizeof(asdl_seq);

	seq = (asdl_seq *)PyArena_Malloc(arena, n);
	if (!seq) {
		PyErr_NoMemory();
		return NULL;
	}
	memset(seq, 0, n);
	seq->size = size;
	return seq;
}

asdl_int_seq *
asdl_int_seq_new(int size, PyArena *arena)
{
	asdl_int_seq *seq = NULL;
	size_t n = (size ? (sizeof(void *) * (size - 1)) : 0);

	/* check size is sane */
	if (size < 0 || size == INT_MIN || 
		(size && ((size - 1) > (PY_SIZE_MAX / sizeof(void *))))) {
			PyErr_NoMemory();
			return NULL;
	}

	/* check if size can be added safely */
	if (n > PY_SIZE_MAX - sizeof(asdl_seq)) {
		PyErr_NoMemory();
		return NULL;
	}

	n += sizeof(asdl_seq);

	seq = (asdl_int_seq *)PyArena_Malloc(arena, n);
	if (!seq) {
		PyErr_NoMemory();
		return NULL;
	}
	memset(seq, 0, n);
	seq->size = size;
	return seq;
}
back to top