if the named buffer already exists, pops it to the front without
 calling the block. otherwise, gets the mode from the block and
 creates a new buffer. returns two things: the buffer, and a boolean
 indicating whether it's a new buffer or not.
170786
def spawn_unless_exists title, opts={}
    new =
      if @name_map.member? title
        raise_to_front @name_map[title] unless opts[:hidden]
        false
      else
        mode = yield
        spawn title, mode, opts
        true
      end
    [@name_map[title], new]
  end
815397
function (buf) {
    if (!(buf instanceof Buffer) || buf.length !== Id.SIZE)
        throw new Error('invalid buffer');
    this._buf = buf;
}
202828
def buffer_focus(self, buf, redraw=True):
        """"""

        # call pre_buffer_focus hook
        prehook = settings.get_hook('pre_buffer_focus')
        if prehook is not None:
            prehook(ui=self, dbm=self.dbman, buf=buf)

        success = False
        if buf not in self.buffers:
            logging.error('tried to focus unknown buffer')
        else:
            if self.current_buffer != buf:
                self.current_buffer = buf
            self.mode = buf.modename
            if isinstance(self.current_buffer, BufferlistBuffer):
                self.current_buffer.rebuild()
            self.update()
            success = True

        # call post_buffer_focus hook
        posthook = settings.get_hook('post_buffer_focus')
        if posthook is not None:
            posthook(ui=self, dbm=self.dbman, buf=buf, success=success)
729428
def add_block(self, name):
        

        if not self.RE_NAME.match(name):
            raise ValueError(u"Invalid block name '{0}'"
                             .format(common.from_utf8(name)))

        if name in self._block_map:
            raise ValueError(u"Block '{0}' already exists"
                             .format(common.from_utf8(name)))

        # add new block and index mapping
        self._block_map[name] = len(self._ast[2])  # must come first
        option_list = []
        block = [name, option_list]
        self._ast[2].append(block)
797262
def block_transfer(self, buffer, x, y):
        
        # Just copy the double-buffer cells - the real screen will sync on refresh.
        block_min_x = max(0, x)
        block_max_x = min(x + buffer.width, self._width)

        # Check for trivial non-overlap
        if block_min_x > block_max_x:
            return

        # Copy the available section
        for by in range(0, self._height):
            if y <= by < y + buffer.height:
                self._double_buffer[by][block_min_x:block_max_x] = buffer.slice(
                    block_min_x - x, by - y, block_max_x - block_min_x)
1215315
@Override
	public BufferOrEvent getNextNonBlocked() throws Exception {
		while (true) {
			// process buffered BufferOrEvents before grabbing new ones
			Optional<BufferOrEvent> next;
			if (currentBuffered == null) {
				next = inputGate.getNextBufferOrEvent();
			}
			else {
				next = Optional.ofNullable(currentBuffered.getNext());
				if (!next.isPresent()) {
					completeBufferedSequence();
					return getNextNonBlocked();
				}
			}

			if (!next.isPresent()) {
				if (!endOfStream) {
					// end of input stream. stream continues with the buffered data
					endOfStream = true;
					releaseBlocksAndResetBarriers();
					return getNextNonBlocked();
				}
				else {
					// final end of both input and buffered data
					return null;
				}
			}

			BufferOrEvent bufferOrEvent = next.get();
			if (isBlocked(bufferOrEvent.getChannelIndex())) {
				// if the channel is blocked, we just store the BufferOrEvent
				bufferBlocker.add(bufferOrEvent);
				checkSizeLimit();
			}
			else if (bufferOrEvent.isBuffer()) {
				return bufferOrEvent;
			}
			else if (bufferOrEvent.getEvent().getClass() == CheckpointBarrier.class) {
				if (!endOfStream) {
					// process barriers only if there is a chance of the checkpoint completing
					processBarrier((CheckpointBarrier) bufferOrEvent.getEvent(), bufferOrEvent.getChannelIndex());
				}
			}
			else if (bufferOrEvent.getEvent().getClass() == CancelCheckpointMarker.class) {
				processCancellationBarrier((CancelCheckpointMarker) bufferOrEvent.getEvent());
			}
			else {
				if (bufferOrEvent.getEvent().getClass() == EndOfPartitionEvent.class) {
					processEndOfPartition();
				}
				return bufferOrEvent;
			}
		}
	}
42715
private CallbackResult<Boolean> renderBlock(BufferBuilder buffer, IBlockAccess world, BlockPos pos, IBlockState state)
	{
		IBlockRenderer renderer = getBlockRendererOverride(world, pos, state);
		if (renderer == null)
			renderer = blockRenderers.get(state.getBlock());
		if (renderer == null)
			return CallbackResult.noResult();

		//convert pos to immutable one
		return CallbackResult	.<Boolean> builder()
								.value(renderer.renderBlock(buffer, world, new BlockPos(pos), state))
								.withReturn(true)
								.result();
	}
557462
private boolean skipToInitialBlock()
    {
        int offsetInBlock = (int) (initialOffset % BLOCK_SIZE);
        long blockStartLocation = initialOffset - offsetInBlock;

        // Don't search a block if we'd be in the trailer
        if (offsetInBlock > BLOCK_SIZE - 6) {
            blockStartLocation += BLOCK_SIZE;
        }

        endOfBufferOffset = blockStartLocation;

        // Skip to start of first block that can contain the initial record
        if (blockStartLocation > 0) {
            try {
                fileChannel.position(blockStartLocation);
            }
            catch (IOException e) {
                reportDrop(blockStartLocation, e);
                return false;
            }
        }

        return true;
    }
581671
def get_raw_fixed_block(self, unbuffered=False):
        """"""
        if unbuffered or not self._fixed_block:
            self._fixed_block = self._read_fixed_block()
        return self._fixed_block
250628
private ByteBuffer getBuffer() throws IOException {
        ByteBuffer buffer;

        // Get the oldest block that has a buffer
        int bufferCount = 0;
        TableBlock takeFromBlock = null;
        for (TableBlock block : _blocks) {
            if (block.hasBuffer()) {
                bufferCount++;
                if (takeFromBlock == null || block.getMostRecentUse() < takeFromBlock.getMostRecentUse()) {
                    takeFromBlock = block;
                }
            }
        }
        if (bufferCount < _bufferCount || takeFromBlock == null) {
            // We haven't used the maximum number of buffers yet, so allocate a new one
            _log.debug("Allocating new block of size {}", _blockSize);
            buffer = ByteBuffer.allocate(_blockSize);
        } else {
            buffer = takeFromBlock.flushAndReleaseBuffer();
            // Reset the buffer for reuse
            buffer.position(0);
            buffer.limit(_blockSize);
        }

        return buffer;
    }
399718
def pop
      # NOTE: can't use popstr because the data might be binary
      ptr = ffi_delegate.pop
      return nil if ptr.null?
      Frame.from_ffi_delegate(ptr).to_s
    end
809516
def enter_block(self, name):
        """"""
        section = self._get_section(name)
        block = self.current_block = section.new_block()
        self.blocks.append(block)
        return block
1118167
private Mode lookupCreateMode(String name) {
    if (name == null)
      return null;
    name = name.trim();
    Mode mode = (Mode)modeMap.get(name);
    if (mode == null) {
      mode = new Mode(name, defaultBaseMode);
      modeMap.put(name, mode);
    }
    return mode;
  }
68751
def get_boolean(self, name):
        
        for interface in self.all_interfaces:
            if isinstance(interface, VlanInterface):
                if any(vlan for vlan in interface.interfaces
                       if getattr(vlan, name)):
                    return True
            else:
                if getattr(interface, name):
                    return True
        return False
107583
def get_or_create(cls, name):
        
        obj = cls.query.filter_by(name=name).one_or_none()
        if obj:
            return obj
        try:
            with session.begin_nested():
                obj = cls(name=name)
                session.add(obj)
                session.flush()
            return obj
        except IntegrityError:
            log.debug('Collision when adding %s(name="%s"), returning existing object',
                      cls.__name__, name)
            return cls.query.filter_by(name=name).one()
427515
def has(self, block, name):
        
        try:
            self.get(block, name)
            return True
        except KeyError:
            return False
177774
def _pop(self, block=True, timeout=None, left=False):
        
        item  = None
        timer = None
        deque = self._deque
        empty = IndexError('pop from an empty deque')

        if block is False:
            if len(self._deque) > 0:
                item = deque.popleft() if left else deque.pop()
            else:
                raise empty
        else:
            try:
                if timeout is not None:
                    timer = gevent.Timeout(timeout, empty)
                    timer.start()

                while True:
                    self.notEmpty.wait()
                    if len(deque) > 0:
                        item = deque.popleft() if left else deque.pop()
                        break
            finally:
                if timer is not None:
                    timer.cancel()

        if len(deque) == 0:
            self.notEmpty.clear()

        return item